如何接收意图.ACTION_PACKAGE_ADDED意图.appwidget中的ACTION_PACKAGE_REMOVED?

her*_*rtD 4 android widget android-intent

如何接收Intent.ACTION_PACKAGE_ADDEDIntent.ACTION_PACKAGE_REMOVED在appwidget?

我试图在Manifest中添加intent-filter:

 <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>
Run Code Online (Sandbox Code Playgroud)

我也尝试在代码中注册:

@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);

   }
Run Code Online (Sandbox Code Playgroud)

但两者都没有用.谢谢!

pzu*_*ulw 8

在AndroidManifest.xml中添加<data android:scheme="package" />解决了这个问题.

<receiver android:name=".PackageAddedReceiver">
    <intent-filter>
        <action android:name="android.intent.action.PACKAGE_ADDED"/>
        <data android:scheme="package" />
    </intent-filter>
</receiver>
Run Code Online (Sandbox Code Playgroud)