Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 323
herbertD Avatar asked Dec 16 '22 21:12

herbertD


1 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>
like image 50
pzulw Avatar answered Dec 18 '22 10:12

pzulw