Adding the App WidgetProvider Info metadata

For a widget, the values in the AppWidgetProviderInfo structure are supplied in an XML resource. In the example above, the xml resource is referenced with android:resource="@xml/appwidget_info". That XML file would go in your application's directory at res/xml/appwidget_info.xml. Here is a simple example.

<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" android:minWidth="4 0dp" android:minHeight="30dp" android:updatePeriodMillis="8 6 40 0 00 0" android:initialLayout="@layout/test_appwidget"

android:configure="com.android.tests.appwidgethost.TestAppWidgetConfigure" >

</appwidget-provider>

The attributes are as documented in the AppWidgetProviderInfo class. Using the AppWidgetProvider class

The AppWidgetProvider class is the easiest way to handle the widget provider intent broadcasts. See the src/com/example/android/apis/appwidget/ExampleAppWidgetProvider.java sample class in ApiDemos for an example.

Keep in mind that since the the AppWidgetProvider is a BroadcastReceiver, your process is not guaranteed to keep running after the callback methods return. See Application Fundamentals > Broadcast Receiver Lifecycle for more information.

0 0

Post a comment