Question

I have a home widget as follow.

<receiver android:name="org.yccheok.gui.widgetMyAppWidgetProvider"
    android:exported="true" >
    <intent-filter >
        <action android:name="android.intent.action.MEDIA_MOUNTED" />
        <data android:scheme="file"/>

        <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
        <action android:name="android.appwidget.action.APPWIDGET_ENABLED" />
        <action android:name="android.appwidget.action.APPWIDGET_DELETED" />
        <action android:name="android.appwidget.action.APPWIDGET_DISABLED" />
        <action android:name="android.appwidget.action.APPWIDGET_OPTIONS_CHANGED" />
    </intent-filter>

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

I wish the widget is able to refresh itself, when the external drive available after device restarting. Hence, that's why I add

<data android:scheme="file"/>

However, I realize that, after I added <data android:scheme="file"/>, the widget can no longer be found in WIDGETS list.

Was it helpful?

Solution

I encountered the same issue and I was unable to get widgets to appear with a <data> tag in the AppWidgetProvider's intent filter, but I was able to create a new receiver which handled those actions separately.

In your AndroidManifest.xml:

<receiver android:name="org.yccheok.gui.widgetMyAppWidgetProvider"
    android:exported="true" >
    <intent-filter >
        <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
        <action android:name="android.appwidget.action.APPWIDGET_ENABLED" />
        <action android:name="android.appwidget.action.APPWIDGET_DELETED" />
        <action android:name="android.appwidget.action.APPWIDGET_DISABLED" />
        <action android:name="android.appwidget.action.APPWIDGET_OPTIONS_CHANGED" />
    </intent-filter>

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

<receiver android:name="org.yccheok.gui.MyOtherProvider"
    android:exported="true" >
    <intent-filter >
        <action android:name="android.intent.action.MEDIA_MOUNTED" />
        <data android:scheme="file"/>
    </intent-filter>
</receiver>

In new class MyOtherProvider.java:

package org.yccheok.gui.MyOtherProvider;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class MyOtherProvider extends BroadcastReceiver
{

    @Override
    public void onReceive(Context context, Intent intent)
    {
        String action = intent.getAction();

        if (Intent.ACTION_MEDIA_MOUNTED.equals(action))
        {
            // do what you want 
            // maybe call a function in your AppWidgetProvider
        }
    }
}

Also, you really only need to include APPWIDGET_UPDATE in your intent filter, as per http://developer.android.com/guide/topics/appwidgets/index.html#Manifest

Hope this helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top