psychotik psychotik - 1 month ago 22
Android Question

Android widget in emulator

I have an existing android app.
I added a simple widget to it using the following:


  • updated my manifest with a
    <receiver>
    block which provides information about my
    AppWidgetProvider
    implementation

  • added a new xml files in res/xml with a
    <appwidget-provider>
    element that contains the height/width/updatePeriod/initialLayout/icon/label attributes

  • added a simple default layout with an
    ImageView
    and a
    TextView

  • implemented my
    AppWidgetProvider



When I build and deploy this to the emulator my Widget doesn't show up in the list of widgets. Am I missing some step to 'install' the widget? Do I need to do anything special to make it appear in the emulator?

EDIT:
Here's what my manifest receiver looks like:

<receiver android:name=".MyAppWidgetProvider"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/my_appwidget_info" />
</receiver>


and here's what my my_appwidget_info.xml looks like:

<?xml version="1.0" encoding="UTF-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:icon="@drawable/ic_logo"
android:label="MySampleApp"
android:minWidth="294dp"
android:minHeight="72dp"
android:updatePeriodMillis="86400000"
android:initialLayout="@layout/my_app_widget" >
</appwidget-provider>

Answer

Does your receiver tag in the manifest have the proper intent-filter and meta-data? It should look like the example in the documentation:

<receiver android:name="MyAppWidgetProvider" >
    <intent-filter>
        <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
    </intent-filter>
    <meta-data android:name="android.appwidget.provider"
               android:resource="@xml/my_appwidget_info" />
</receiver>

The receiver needs both of those pieces to be recognized as an app widget.

Edit: The <receiver> tags also need to be located inside the <application> tags.