Android 4.0: widgets not appearing?

Solution 1:

So here's the solution I came up with:

You need an activity that will appear on the launcher. So first we have ye olde widget receiver, like so:

<receiver android:name=".VolumeProfilesWidget" android:label="@string/app_name">
    <intent-filter>
        <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />                
        <!-- Broadcast Receiver that will also process our self created action -->
        <action android:name="net.thepurge.volumeprofiles.plus.VolumeProfilesWidget.ACTION_WIDGET_RECEIVER"/>               
    </intent-filter>
    <meta-data android:name="android.appwidget.provider" android:resource="@xml/volumeprofiles_widget_provider" />
</receiver>

And then we need some activity, with the MAIN and LAUNCHER set:

<activity android:name=".MainActivity"
          android:label="@string/app_name">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />                
        <action android:name="net.thepurge.volumeprofiles.plus.VolumeProfilesWidget.ACTION_WIDGET_CONFIGURE"/>
    </intent-filter>
</activity>

As far as I can tell you MUST do this even if your widget is just supposed to be a pure widget with no associated activities. At the very least, make one dummy activity that launches a screen that says "Your widget is now ready for use! Look for it under widgets and drag it to your home screen!"

In my case, my widget launched an activity when you pushed it, so I made that activity into LAUNCHER/MAIN and just added a one-time popup dialog that basically says "you can run this as an application but you may want to use the widget instead".

Note that on the 4.0 emulator, I was never getting my widget to show up on a first time install prior to this change. Simply having an activity set to MAIN and LAUNCHER seemed to be enough to make the widget show up.

Solution 2:

After days i figured out the solution

so lets go to any of your activities that will be the launched when you open the app and in the main activity add only this line

sendBroadcast(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME));

as example

public class Default class extends Activity  {


@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
       sendBroadcast(new Intent(Intent.ACTION_MAIN)
       .addCategory(Intent.CATEGORY_HOME));
    setContentView(R.layout.main);



}

that's it , this will give the system that the main app is now running and it will get the widget out to the launcher :) simple line that's it don't modify anything in the manifest just keep the way you developed ur app that shows widget normaly in the previous versions < 4.x

Solution 3:

Got the same problem. I fixed it by deleting <PreferenceScreen> tags in my appwidgetprovider.xml(located in res/xml).

Solution 4:

You need to manually start the associated app at least once to get the widget to show up. Before that it is in a non-runnable state and it won't receive broadcasts, etc.