0
我有一個廣播接收機(BackgroundReceiver),該監聽去除包,然後廣播包的名稱到一個活動(AnalyzeActivity)活動不從廣播接收廣播定製意向接收器
BackgroundReceiver.java
public static final String REMOVED_INTENT = "com.analyze.project.RemovedReceiver";
public void onReceive(Context context, Intent intent) {
String actionStr = intent.getAction();
if (Intent.ACTION_PACKAGE_REMOVED.equals(actionStr)) {
Uri uri = intent.getData();
String pkg = uri != null ? uri.getSchemeSpecificPart() : null;
Log.i("Logging Service", "Package Removed: " + pkg);
//Toast.makeText(context, "Package Removed:" + pkg, Toast.LENGTH_SHORT).show();
Intent c = new Intent();
c.setAction(REMOVED_INTENT);
c.putExtra("Package", pkg);
context.sendBroadcast(c);
}
}
我動態註冊我的AnalyzeActivity內的接收器和監聽定製廣播意圖BackgroundReceiver
AnalyzeActivity.java
@Override
protected void onResume() {
super.onResume();
// Register Sync Recievers
IntentFilter intentToReceiveFilter = new IntentFilter();
intentToReceiveFilter.addAction(BackgroundReceiver.REMOVED_INTENT);
this.registerReceiver(mIntentReceiver, intentToReceiveFilter, null, mHandler);
mReceiversRegistered = true;
}
final BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String Package = intent.getStringExtra("Package");
if (intent.getAction().equals(BackgroundReceiver.REMOVED_INTENT)) {
Toast.makeText(context, "(A) Package Removed: " + Package, Toast.LENGTH_SHORT).show();
Log.i("Package Removed", "(A) Package Removed: " + Package);
}
}
};
但我的活動似乎並不能夠在所有接收廣播意圖。
第一BR是否工作? (BackgroundReceiver) –
我只是想在你的虛擬項目代碼(在這裏我提出從onOptionsItemSelected()方法廣播),它是工作的罰款。當您收到一個自定義的播放您能收到來自系統軟件包刪除廣播... –
是您的活動(如廣播註冊)是可見的? –