Android 如何接收意图。行动方案增加了意图。在appwidget中删除操作\u包\u?
如何在appwidget中接收添加的Android 如何接收意图。行动方案增加了意图。在appwidget中删除操作\u包\u?,android,android-intent,widget,Android,Android Intent,Widget,如何在appwidget中接收添加的Intent.ACTION\u PACKAGE\u和删除的Intent.ACTION\u PACKAGE\u 我已尝试在清单中添加意图筛选器: <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <!-- The widget provider --> &
Intent.ACTION\u PACKAGE\u和删除的Intent.ACTION\u PACKAGE\u
我已尝试在清单中添加意图筛选器:
<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>
但两者都不起作用。
谢谢
当我的自定义启动器收到删除/添加的包消息时,我会向我的小部件发送广播。这是我找到的唯一解决方法。在AndroidManifest.xml中添加
解决了这个问题
<receiver android:name=".PackageAddedReceiver">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED"/>
<data android:scheme="package" />
</intent-filter>
</receiver>
在添加或删除您自己的软件包时,您是否尝试接听电话?因为这不起作用:Hi Time,“请注意,新安装的软件包不接收此广播”是什么意思?多长时间可以算作“新的”?呃,很抱歉这个定义不清楚。对于新安装的包,我指的是包含此代码的包。如果您使用此代码安装软件包,则在删除时也不会通知它。谢谢。我不是在这种情况下。我想在另一个显示apk状态的小部件中接收消息。您可以尝试将
添加到意图过滤器中吗?实际上,您可以在清单中使用意图。你只需要处理onReceive而不是onUpdate。作为这个答案的补充,这里的关键是“android:scheme”,它在OP的原始清单中丢失了。在Java中,可以这样设置方案:filter.addDataScheme(“package”);
<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>
<receiver android:name=".PackageAddedReceiver">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED"/>
<data android:scheme="package" />
</intent-filter>
</receiver>