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!
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With