Android widget not showing up on the list after developed
Asked Answered
N

8

25

I'm upgrading my app with widget. It's not the first widget I've done. I was always encountering weird issues, but the widget was shwoing up on the list eventually.

Here is what I've done so far:

  • Created widget_layout.xml
  • Created widget_info.xml
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"  
    android:minWidth="110dp"
    android:minHeight="30dp"
    android:updatePeriodMillis="86400000"
    android:initialLayout="@layout/widget_layout"
    android:resizeMode="none">
</appwidget-provider>
  • Created WidgetProvider class
  • Added widget to manifest in the <application> section (for some reason can't paste manifest fragment here, it's just not showing, see the code here)

Still, can't find widget on the widgets list. I'm debugging the app on real device. I'm using library project, but the widget files but all in the project I run directly. What could be happening here?

Nasya answered 11/4, 2013 at 12:22 Comment(1)
What if it just does not listed in Android 9?Schramm
N
9

The problem was android:installLocation="preferExternal"

It somehow causes problem with widget list if the app is installed on SD

Nasya answered 12/4, 2013 at 7:35 Comment(2)
this simple code helped a lot and saved me a lot of time. thank youWinters
In fact, appwidgets were always incompatible with SD installation. Users don't get any warning from Android, widgets just don't appear in the listWood
T
29

Ran across similar issues and this is what happened for me. The below Widget never showed up in the Widget drawer till minResizeHeight was added. Weird, but may be that is required for resizable widget. Could have been more friendly.

<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:initialLayout="@layout/pmt_schedule_scroll_widget"
android:minHeight="146dip"
android:minResizeHeight="73dp"
android:minWidth="146dip"
android:resizeMode="vertical"
android:updatePeriodMillis="0" />
Torras answered 8/7, 2013 at 3:44 Comment(1)
I am using resizeMode="none" and it still helped to add minResizeHeight and minResizeWidth.Guerra
G
24

This kind of issue can happen with 2 scenarios. Both are answered above and this is a complete answer and I have faced both the scenarios and resolved both of them.

Scenario1

If the application specifies android:installLocation="preferExternal" parameter in manifest, App will be installed in external memory and it will not show in the widget list. Also if you have made your phone to install all the apps on sd card, this will also happen.

solution

Go to Settings->Apps->YourApp Then "move to phone". This will move the app to your phone memory and now you can see the widget in your widget list

Scenario2

If the above fix did not solve your issue, then you may have a device with android 4.X.X version.

Then you have to set at least following parameters in widget_info.xml file

solution2

android:minHeight="XXXdp" android:minWidth="XXXdp"

Guava answered 20/8, 2013 at 6:12 Comment(1)
To add to this, if the minHeight and/or minWidth are too large, it will not show up in the widget list. After changing to a smaller res, it will show upHouseroom
N
9

The problem was android:installLocation="preferExternal"

It somehow causes problem with widget list if the app is installed on SD

Nasya answered 12/4, 2013 at 7:35 Comment(2)
this simple code helped a lot and saved me a lot of time. thank youWinters
In fact, appwidgets were always incompatible with SD installation. Users don't get any warning from Android, widgets just don't appear in the listWood
A
8

I tried every possible solution and nothing worked for me... And finally I solved it.

In my case the problem was overthinking: I believed that in meta-data tag we need to define a unique name for provider (eg: "com.example.myprovider") as well as link to the xml resource.

Wrong:

<meta-data
      android:name="com.example.myprovider"
      android:resource="@xml/widget_info" />

Right:

<meta-data
  android:name="android.appwidget.provider"
  android:resource="@xml/widget_info" />
Avi answered 17/12, 2015 at 13:39 Comment(1)
I was linking to the widget layout in the android:resource instead of widget info :-LOLHubbell
M
5

You need to register a BroadcastReceiver in the manifest file. For example:

<receiver
   android:icon="@drawable/icon"
   android:label="Example Widget"
   android:name="MyWidgetProvider" >
   <intent-filter >
        <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
   </intent-filter>

   <meta-data
      android:name="android.appwidget.provider"
      android:resource="@xml/widget_info" />
</receiver> 

I borrowed this code from http://www.vogella.com/articles/AndroidWidgets/article.html

See the link for a full tutorial

Mayenne answered 11/4, 2013 at 13:14 Comment(0)
T
2

after hours of searching and failing to resolve, I decided to open a sample project of a widget that works and go comparing item by item to see what was wrong, in the end, I solve added the following lines on my res/xml/widget_info.xml:

android:minHeight="XXXdp"
android:minResizeHeight="XXXdp"
android:minResizeWidth="XXXdp"
android:minWidth="XXXdp"

where XXX is some value.

Thanksgiving answered 29/6, 2013 at 9:39 Comment(1)
This was the culprit for me as well.Gooseflesh
W
2

In my case, the issue was in the intent-filter within the receiver.

Wrong:

<intent-filter>
    <action android:name="APPWIDGET_UPDATE" />
</intent-filter>

Correct:

<intent-filter>
    <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
Wolcott answered 11/1, 2019 at 18:23 Comment(0)
A
1

In my case, it was the minWidth, it was too large, just put a smaller dp, it works also with a minHeight too height as well!

Anxious answered 23/9, 2020 at 19:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.