Android widgets provide a way to display a view of the app to the user on the homescreen or keyguard. When building widgets, you have full access to the Airship SDK, including access to the app's Message Center.
The following example code shows how to create a home screen widget that lists the messages. This example utilizes the RemoteViewsService class in order to display a collection in a widget, making the widget incompatible with Android Gingerbread.
In order to display the inbox, the App Widget needs to be backed by a RemoteViewsService. The RemoteViewsService is responsible for providing a RemoteViewsFactory that builds the list item views for the App Widget.
The next step is to create an AppWidgetProvider. The AppWidgetProvider is a broadcast receiver used to communicate with the App Widget. Its primary responsibility is to update the App Widget.
// embed the appWidgetId via the data otherwise it will be ignored.
// view of the collection view.
Before the App Widget can be added to the main screen, you must provide details about the widget.
Now the Message Center Inbox should be able to be added to the home screen. It will display the messages in a list view and update every 30 minutes (defined by the App Widget info).
Displaying a list of inbox messages is not very useful if the user cannot interact with the messages. Click events can be captured in the App Widget by providing a pending intent to be fired when a remote view is clicked. For this example, we will set up a pending intent that sends a broadcast with the ID of the message that was clicked back to the AppWidgetProvider.
The widget will only refresh its content every 30 minutes. However, the inbox could be updated during this interval. To keep the inbox up-to-date, add a listener to the inbox that refreshes the widget.