Development

Creating a Provider

A Smart Bulletin provider is a kind of app widget. Therefore, the development process for Smart Bulletin providers is basically the same as that for app widgets. The following are the steps in the development process:

  1. Creating an Android Project

  2. Developing an App widget

  3. Making an App widget as a Provider

Creating an Android Project

Create an Android application project in the following order.

 

This document only describes the process of developing an Android project using Eclipse.

 

1) Go to File > New > Project in Eclipse.

 

2) Select Android > Android Application Project in the window that appears and click Next.

 

3) Fill in the 'Application Name', 'Project Name' and 'Package Name' fields and click Next.

 

4) Uncheck 'Create custom launcher icon' and 'Create activity' and then click Finish.

 

You may have to create a custom launcher icon and activity depending on the characteristics of the application you will implement.

Developing an App Widget

To create an app widget, you need to declare an app widget in the manifest file, configure widget provider information, specify a layout for the app widget and implement the app widget provider.

 

This document does not give a detailed description of how to create and implement an app widget; this is beyond the scope of this document. For detailed information, check out Android Developer >.

Making an App Widget as a Provider

To make an app widget you created into a Smart Bulletin provider, you need to modify the metadata of the app widget provider so that Smart Bulletin can recognize it as a provider.

 

Modifying Metadata

Open your app widget's metadata file (e.g., res/xml/appWidgetProvider.xml) and add the following attribute to the <appwidget-provider> tag.

android:widgetCategory="0x100"

 

When you run the application, Smart Bulletin recognizes this app widget as a Smart Bulletin provider and adds it on the available provider list.

 

Setting Height of the Root Layout

One difference between Smart Bulletin providers and app widgets is that the height of Smart Bulletin providers is flexible, while that of app widgets is fixed. As mentioned in UI Elements, providers can add or remove content dynamically. Therefore the height of providers should be automatically adjusted to show all the contents.

To do this, the height of the root layout must be "wrap_content".

 

The following is an example of the layout XML file that sets the height of the uppermost layout, LinearLayout, as "wrap_content".

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:showDividers="end" >
    ...
</LinearLayout>

 

Unlike app widgets, Smart Bulletin providers do not provide configuration activities. When you convert an app widget with a configuration activity into a provider, you must provide a way to open the configuration activity.

 

Specifying Titles

You can specify the titles that appear in provider headers and the list on the Settings screen, in the AndroidManifest.xml file. You can specify these by specifying the android:label attribute of the <receiver> tag of the app widget provider that creates the provider.

Setting Additional Information

Smart Bulletin uses an app widget's label as the title of the content and uses the screen defined by the app widget as the layout. However, you have to specify separately a full-screen application that will run when the title of the provider is tapped, as well as the background and title colors that will be displayed in the header of the provider.

Setting Full-Screen Activities

A Smart Bulletin provider allows you to specify a full-screen application that will run when the title is tapped. You have to define a full-screen application in a resource file.

 

Add the following XML file to the res/values/ folder of the project.

<resources>
    <string name="smartbulletin_provider_default_activity">
        com.example.sbprovider/com.example.sbprovider.MyActivity
        <!-- full screen activity -->
    </string>
</resources>

 

  • smartbulletin_provider_default_activity: Specifies a component that will run when the title of the provider is tapped. If you do not specify any component, no action is performed.

 

Setting Default Colors

A Smart Bulletin provider enables you to specify the background and title colors of content. You have to define the default colors for content in a resource file.

 

Add the following XML file to the res/values folder of the project.

<resources>
    <color name="smartbulletin_provider_bg_color">
        #ffd66391   <!-- background color -->
    </color>
    <color name="smartbulletin_provider_title_color">
        #ffffffff   <!-- title text color -->
    </color>
</resources>

 

  • smartbulletin_provider_bg_color: Specifies a background color in ARGB format.
  • smartbulletin_provider_title_color: Specifies a title color in ARGB format.

 

If you do not specify either one of the two items above, Smart Bulletin randomly picks a background color and a title color.

 

When defining a full-screen application and content colors, you must use the same resource file.

Changing Colors Dynamically

In the above section, we have learned how to specify the background and title colors of provider. These colors are applied when provider is initially attached.

 

To dynamically change provider’s colors after it is attached, a color change request must be sent to Smart Bulletin. These requests are transmitted through broadcast intents. The following is the information that must be transmitted when broadcasting:

 

  • component_name (the name of the component whose colors you want to change): A required item. It specifies the provider whose colors you want to change. The component name of the provider must be transmitted.
  • background_color (the background color you want to use): It specifies a background color in ARGB format. If you do not specify any color, white is selected by default.
  • title_color (the title color you want to use): It specifies a title color in ARGB format. If you do not specify any color, black is selected by default.

 

To dynamically change colors, send a color change request as shown below.

Intent intent = new Intent
          ("com.lge.launcher2.smartbulletin.configuration.color");
intent.putExtra("component_name",
                   "com.example.sbprovider/" +
                   "com.example.sbprovider.MyProvider");
intent.putExtra("background_color", Color.RED);
intent.putExtra("title_color", Color.WHITE);
context.sendBroadcast(intent);

 

For detailed information on intents relevant to color change requests, see Intents for Color Change.

Issuing Notifications

A provider can issue notifications to inform users of news or job processing. Providers send notifications to Smart Bulletin through broadcast intents. The following is the information that must be transmitted when broadcasting:

 

  • noti_type (the type of the notification): A required item. It specifies whether the notification is a one-shot (once) notification or an ongoing notification.
  • component_name (the notification component): A required item. It specifies the provider that issues the notification. The component name of the provider must be transmitted.
  • resource_uri (the notification icon): The notification icon that you want to display in Smart Bulletin’s title area. This item is valid when you issue ongoing notifications, and the URI of the notification icon must be transmitted. If you do not specify a notification icon, the default icon specified in the manifest file is displayed. In case of one-shot (once) notifications, this item is ignored and the default icon provided by Smart Bulletin is displayed.

 

The notification type and the notification component, both of which are required items, must be filled in. Otherwise, an error occurs, or no notification is issued.

 

For information on intents relevant to notifications, see Intents for Notifications.

Sending Notifications

To issue one-shot (once) notifications, transmit an intent as shown below.

Intent intent = new Intent
        ("com.lge.launcher2.smartbulletin.ADD_NOTIFICATION_ICON");
intent.putExtra("noti_type", "once");
intent.putExtra("component_name", 
                   "com.example.sbprovider/" +
                   "com.example.sbprovider.MyProvider");
context.sendBroadcast(intent);

 

To issue ongoing notifications, use the following code.

Intent intent = new Intent
        ("com.lge.launcher2.smartbulletin.ADD_NOTIFICATION_ICON");
intent.putExtra("noti_type", "ongoing");
intent.putExtra("resource_uri",
                   "android.resource://com.example.sbprovider/" +
                   "drawable/ic_launcher");
intent.putExtra("component_name", 
                   "com.example.sbprovider/" +
                   "com.example.sbprovider.MyProvider");
context.sendBroadcast(intent);

Removing Notifications

To remove issued notifications, send an intent as shown below. An intent for the removal of notifications invariably removes notification icons shown on the screen regardless of the notification type, you do not need to specify noti_type.

Intent intent = new Intent
("com.lge.launcher2.smartbulletin.REMOVE_NOTIFICATION_ICON");
intent.putExtra("component_name",
                   "com.example.sbprovider/" +
                   "com.example.sbprovider.MyProvider");
context.sendBroadcast(intent);

 

Because ongoing notifications must be removed explicitly by the provider, it is essential to use the code above at some point in time. One-shot (once) notifications disappear when the user taps the provider that issues notifications. However, you can use the code above in cases where it is necessary to remove one-shot (once) notifications without users' requests.

Monitoring Smart Bulletin Status

Smart Bulletin broadcasts its status such as user-configured information on whether it is used or not. For a provider to perform a specific task using such information, you need to create a BroadcastReceiver to receive intents sent from Smart Bulletin.

For information on intents relevant to the Smart Bulletin's status, see Intents for Smart Bulletin Status.

 

Check out Handling Smart Bulletin Status Intents for information on codes used to receive the Smart Bulletin's status broadcasts.

Monitoring Provider Status

Smart Bulletin notifies attachment status of each provider.

When the user makes each provider attach to or detach from Smart Bulletin in the settings screen, Smart Bulletin sends Intent to the provider. Receive the Intent to perform actions that are needed when your provider is attached or detached.

 

For information on intents relevant to the provider’s attachment status, see Intents for Provider Status.

 

Navigation