0
我想在包被移除時捕獲事件。 我使用以下命令: 一個BroadcastReceiver子類:使用BroadcastReceiver捕獲PACKAGE_REMOVED事件
public class CustomBroadcastReceiver extends BroadcastReceiver {
/**
* This method captures the event when a package has been removed
*/
@Override
public void onReceive(Context context, Intent intent)
{
Helper.writeInLogFile("Hello from CustomBroadcastReceiver");
if (intent != null) {
String action = intent.getAction();
if (action.equals(intent.ACTION_PACKAGE_REMOVED)) {
//Log the event capture in the log file ...
Helper.writeInLogFile("The package has been removed");
}
}
}
}
與它的清單部分:
<receiver android:name="CustomBroadcastReceiver" >
<intent-filter>
<action android:name="android.intent.action.PACKAGE_REMOVED" >
</action>
</intent-filter>
</receiver>
...但CustomBroadcastReceiver不會觸發。我究竟做錯了什麼? 謝謝
你在那裏看到的東西看起來確實沒問題,儘管'intent'永遠不會是'null',所以特定的測試並不是特別有用。 – CommonsWare
好的測試 - 我只是做了它,因爲我想確保動作測試不會失敗到一個例外有時(事實上,我保證自己反對我的Android內部消息系統的無知)。這表示,拿出整個代碼,除了登錄到文件,它仍然不執行CustomBroadcastReceiver ... –