views:

67

answers:

2

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>
+2  A: 

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.

tinja
Thanks, yes it does.
psychotik
Hmm, well it looks like you have everything necessary to show up in the widget list. I copied the code you provided into a fresh project and the widget showed up in the list for me.You're not getting any errors when you deploy?
tinja
nope, no errors. I even tried to uninstall my app and re-install. Other suggestions?
psychotik
Your <receiver> tag needs to be located inside your <application> tags. If <receiver> is outside of <application>, it won't throw any errors, but it won't recognize the <receiver> at all.
tinja
^ This was it - I had the XML outside my <application> tags. Thanks!
psychotik
A: 

If your app is installed on the SD card, all your widgets will quietly refuse to show up in the list. (The docs do make it clear that you can't have widgets if you're on the external storage).

You can go to the settings in the home screen, go to Applications, and go to your app. If it offers you to "Move to phone", then it is on the SD card. You can set the install location to internalOnly to prevent it from going onto the SD card.

If you do allow installation on SD card (because users will typically ask for that), they need to be clear that they can't have the widget in that case. If an app is on SD card and you want to use the widget, you first have to move the app back to internal storage and then reset the phone (!).

EboMike
That's good info - thanks. But in my emulator I am installing to main memory. I have even run this on emulators without any SD card.
psychotik