Android 4.0: widgets not appearing?
Asked Answered
C

5

27

I have a widget I created against Android 2.1 that's been fine and selling on the market.

I had a user complain that he bought it and it never showed up on his Android 4.0 device.

I loaded up the 4.0 emulator, ran it from Eclipse, it reported a successful installation and in fact I can see it listed in the "Widget Preview" app, and I can run it there and it seems fine, but it doesn't show up anywhere under "Widgets" -- I can't actually find it to drag it to the home screen! I assume this is the same thing the user is seeing.

Any idea what's going on here? Why is it fine in 2.1 but doesn't show up in the list on 4.0, even after a successful install?

This is my layout\widget.xml file, if that's any help:

<RelativeLayout android:id="@+id/relativeLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android">
    <TextView android:layout_width="wrap_content" android:id="@+id/blankspot" android:layout_height="5dp" android:gravity="center" android:shadowDy="1" android:shadowDx="1" android:layout_centerHorizontal="true"></TextView> 
    <ImageButton android:layout_below="@+id/blankspot" android:layout_width="60dp" android:layout_height="60dp" android:id="@+id/widgetIconButton" android:layout_centerHorizontal="true" android:scaleType="centerCrop" android:src="@drawable/volumeprofilesplus" android:background="@null"></ImageButton>
    <ImageView android:layout_width="60dp" android:layout_height="20dp" android:id="@+id/override" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:scaleType="fitXY" android:background="@null" android:src="@drawable/overredcaps" android:visibility="invisible"></ImageView>
    <ImageButton android:layout_below="@+id/widgetIconButton" android:layout_width="70dp" android:layout_height="30dp" android:id="@+id/widgetSettingsButton" android:layout_centerHorizontal="true" android:scaleType="fitXY" android:src="@drawable/settings" android:background="@null"></ImageButton>
</RelativeLayout>

And the xml\widget_provider.xml:

<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:minWidth="72dip"
    android:minHeight="72dip"
    android:updatePeriodMillis="0"
    android:initialLayout="@layout/main" >    
</appwidget-provider>
Cooperate answered 9/1, 2012 at 20:44 Comment(5)
Please post your {widget}.xmlSpann
Manifest or provider xml? Lemme figure out how to paste code correctly...Cooperate
layouts\widget.xml - is that a "typo" or is your provider xml really in the layout folder? Should rather be in res/xml/widget.xml.Oersted
Yeah whoops, pasted the wrong thing. Fixed it up. I can post the manifest too but it's rather lengthy. I run this fine on my Thunderbolt (2.3.4) and it shows up in the downloaded list and is actually running, but I see no way to bring it to the desktop. I scrolled all through the widgets list on the 4.0 emulator and it's not showing up.Cooperate
Uh. Huh. So it just appeared after I rebooted the device. So I guess the answer is "sometimes you have to just reboot your device"? I'll leave this as a question for now in case there really is something I'm supposed to have in my XML.Cooperate
C
17

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.

Cooperate answered 15/1, 2012 at 1:6 Comment(4)
Is this only an issue with the emulator or does this affect Android 4.0 devices as well?Dispatcher
Apparently it does. See Issue 24208Dispatcher
Yeah it's on devices too. I first heard about it from a customer who bought my app for a 4.0 device and couldn't find it. He was able to make it appear by rebooting but I don't think "shut up and reboot" is a very good solution, long term. (Although it worked for Microsoft for years.)Cooperate
This is ridiculous that we have to clutter up the user's App Launcher to make it work on certain versions of Android, but your solution seems to be the fix.Engeddi
B
9

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

Burmeister answered 10/1, 2013 at 18:41 Comment(0)
T
3

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

Turning answered 17/10, 2012 at 9:3 Comment(1)
I never had PreferenceScreen tags anywhere.Cooperate
T
1

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.

Tope answered 10/1, 2012 at 3:22 Comment(4)
Ah, so it might have been a coincidence that I saw it on reboot, and what really got it on there was opening it in the widget preview? Other than the widget preview, how else can we tell people to "manually start the associated app"? Technically it's just a widget -- there is nothing to show up under "applications".Cooperate
Could be, I haven't actually looked into this in detail. Add a simple test activity and try it out. If it turns out this is required, you could use it to change settings, give instructions, etc. Not ideal, I agree.Tope
I voted down because I don't think this is try. I have a pure widget that I used without ever running an associated app, on 2.3 & 4.1. I must admit that I'm here because that widget later become wonky, but for a while it worked fine as a 'pure widget'.Kronstadt
@NikolayElenkov - hi, i seem not to see my widget in the list of widgets only in android 4.4 , it works well with the other versions of android, i have the launcher activity too. What could be the issue? I tried restarting my device also. Please help.Downy
D
0

My solution (Widget on 4.1.2) was be sure that widget was installed on the internal device storage.

According to: Android Documentation: install-location, you should not install widgets on External Storage.

I had to uninstall my widget, install it again and after that i saw the changes !

Useful link:

http://www.technipages.com/fix-android-app-widgets-not-appearing-on-widget-list

Donata answered 13/9, 2015 at 18:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.