psychotik
psychotik

Reputation: 39019

Android widget in emulator

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

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>

Upvotes: 5

Views: 6201

Answers (6)

jef
jef

Reputation: 283

I had the same problem then I finally figure it out. Usually when you emulate an application, it has an activity to load. For a widget-only app, that isn't the case, but the IDE still thinks you're trying to launch an activity.

To change this go to your Build Options

Example

then change the Launch Options to Nothing

Example

Upvotes: 0

Sam
Sam

Reputation: 5392

I had the same issue as well. A few things to check that can stop it from showing up on different models.

1)Must have a minHeight and minWidth set on AppWidget-Provider in the xml, if you remove either of those and launch in emulator, your widget will be gone. 2)Some models have issues if you don't supply a previewImage in the AppWidget-Provider 3)Some models can have issues if you install on the SD Card rather than internally, although I still prefer to install on SD Card. 4)Some models need to have an Activity with Main and Launcher defined even if you don't intend on using any Activities. (You can simply make a dummy one that says 'this is a widget app only' 5)You have to have your manifest setup correctly as shown in TinJa's answer.

I fought through this for quite a while before finally getting it to show up in all models and emulators, so be patient, make sure you aren't missing anything and set the values that need to be there. Remember some phones cache the Widget List and may not update until you have launched your first Activity or Rebooted the phone.

Hope that helps.

Sam

Upvotes: 1

Oded BD
Oded BD

Reputation: 3276

I had the same problem. And my problem was that I have /layout/main.xml file when I delete it the widget appear!

It sound like @ubzack answer but I think he talk about something else [same xml file name]

Upvotes: -1

ubzack
ubzack

Reputation: 1876

I had the same problem. It turned out I accidentally had two meta-data resource xml files in two different folders, my "layout" folder and my "xml" folder. It was finding the (empty) resource in "layout" first, and using that for its meta-data.

It was a stupid mistake, but make sure you have only one xml file of that name that's pointed to in your receiver meta-data tag. Also I think it should always be in the xml folder.

Upvotes: -1

tinja
tinja

Reputation: 161

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.

Upvotes: 6

EboMike
EboMike

Reputation: 77732

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 (!).

Upvotes: 1

Related Questions