如何在appwidget中接收Intent.ACTION_PACKAGE_ADDED
和Intent.ACTION_PACKAGE_REMOVED
?如何接收意圖。 ACTION_PACKAGE_ADDED意圖。 ACTION_PACKAGE_REMOVED在appwidget中?
我一直在努力,在清單中添加的意圖過濾器:
<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>
,我也試過寄存器代碼:
@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);
}
但兩者沒有工作。 謝謝!
當您添加或刪除自己的包時,您是否試圖接聽電話?因爲這不起作用:http://developer.android.com/reference/android/content/Intent.html#ACTION_PACKAGE_ADDED – 2012-07-29 12:23:32
嗨,時間,什麼是「請注意,新安裝的軟件包不會收到此廣播。 「?多久可以算作「新」? – herbertD 2012-07-30 01:41:45
對不起,這個不清楚的定義。對於新安裝的軟件包,我的意思是包含此代碼的軟件包。如果您使用此代碼安裝您的軟件包,則不會在您將其刪除時收到通知。 – 2012-07-30 10:24:15