How to receive Intent. ACTION_PACKAGE_ADDED Intent. ACTION_PACKAGE_REMOVED in appwidget?

How to receive Intent.ACTION_PACKAGE_ADDED and Intent.ACTION_PACKAGE_REMOVED in appwidget?

I've tried to add intent-filter in Manifest:

 <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <!-- The widget provider -->
        <receiver android:name=".NetsWidgetProvider">
            <intent-filter>
                <action android:name="android.intent.action.PACKAGE_REMOVED"/>
                <action android:name="android.intent.action.PACKAGE_ADDED"/>
                <action android:name="com.oozic.widget.incstage.nets.ACTION_NOT_INSTALL"/>
                <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />

            </intent-filter>
            <!-- This specifies the widget provider info -->
            <meta-data android:name="android.appwidget.provider"
                    android:resource="@xml/widgetinfo" />
        </receiver>

    </application>

and I also tried register in Code:

@Override
   public void onEnabled(Context context) {

      registerReceiver(context);
      Utils.log(TAG, "Register PACKAGE_ADDED PACKAGE_REMOVED");

   }

   private void registerReceiver(Context context) {
       IntentFilter filter = new IntentFilter();
       filter.addAction(Intent.ACTION_PACKAGE_ADDED);
       filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
       context.getApplicationContext().registerReceiver(this, filter);

   }

But both didn't work. Thanks!

Answers


In AndroidManifest.xml adding <data android:scheme="package" /> solved the issue.

<receiver android:name=".PackageAddedReceiver">
    <intent-filter>
        <action android:name="android.intent.action.PACKAGE_ADDED"/>
        <data android:scheme="package" />
    </intent-filter>
</receiver>

    <receiver android:name=".NetsWidgetProvider"
        android:label="@string/appwidget_name" android:icon="@drawable/icon">
        <intent-filter>
            <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
            <action android:name="com.oozic.widget.incstage.nets.ACTION_NOT_INSTALL"/>
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.PACKAGE_DATA_CLEARED"/>
            <action android:name="android.intent.action.PACKAGE_REMOVED"/>
            <data android:scheme="package" />
        </intent-filter>
        <!-- This specifies the widget provider info -->
        <meta-data android:name="android.appwidget.provider"
                android:resource="@xml/appwidgetinfo" />
    </receiver>

I send a broadcast to my widget, in my custom launcher when it get the PACKAGE_REMOVED/ADDED message. This is the only work around I found to fix this.


Need Your Help

CORS request issue (XMLHttpRequest)

javascript angularjs node.js

I'm developing a server at Node js and my front-end at Angularjs, but I'm getting an error when I try to make a request from my front-end:

Handle Android Back Button on Phonegap InAppBrowser

android cordova inappbrowser

I would like to disable or override the Android Back button while I am navigating pages on the InAppBrowser. Can I add an event listener that can handle that?