Android widget not showing up on the list after developed-ThrowExceptions

Exception or error:

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?

How to solve:

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" />

###

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”

###

The problem was android:installLocation="preferExternal"

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

###

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" />

###

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

###

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.

###

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>

Leave a Reply

Your email address will not be published. Required fields are marked *