Declaring a widget in the Android Manifest

First, declare the BroadcastReceiver in your application's AndroidManifest.xml file.

<receiver android:name="TestAppWidgetProvider" android:label="@string/oh_hai"

android:icon="@drawable/oh_hai_icon" >

<intent-filter>

<action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> </intent-filter>

<meta-data android:name="android.appwidget.provider" android:resource="@xml/appwidget_info" />

</receiver>

The <receiver> element has the following attributes:

• android:name - specifies the BroadcastReceiver or AppWidgetProvider class.

• android:label - specifies the string resource that will be shown by the widget picker as the label.

• android:icon - specifies the drawable resource that will be shown by the widget picker as the icon.

The <intent-filter> element tells the PackageManager that this BroadcastReceiver receives the AppWidgetManager.ACTION APPWIDGET UPDATE broadcast. The widget manager will send other broadcasts directly to your widget provider as required. It is only necessary to explicitly declare that you accept the AppWidgetManager.ACTION APPWIDGET UPDATE broadcast.

The <meta-data> element tells the widget manager which xml resource to read to find the AppWidgetProviderInfo for your widget provider. It has the following attributes:

• android:name="android.appwidget.provider" - identifies this meta-data as the AppWidgetProviderInfo descriptor.

• android:resource - is the xml resource to use as that descriptor.

0 0

Post a comment