her*_*rtD 4 android widget android-intent
如何接收Intent.ACTION_PACKAGE_ADDED和Intent.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)
但两者都没有用.谢谢!
在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)
| 归档时间: |
|
| 查看次数: |
9519 次 |
| 最近记录: |