Android:无法接收PACKAGE_REMOVED广播

时间:2012-08-29 16:35:24

标签: android broadcastreceiver

我有我的接收者代码

    BroadcastReceiver pkgRemoveReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            // do my stuff
        }
    };
    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    registerReceiver(pkgRemoveReceiver, filter);

因此,每当从设备中删除应用程序时,我都会做一些簿记。但是,我无法接收广播。上面的代码有问题吗?

THX! 拉胡

1 个答案:

答案 0 :(得分:4)

尝试:

   IntentFilter filter = new IntentFilter();
   filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
   filter.addDataScheme("package"); // add addDataScheme
   registerReceiver(pkgRemoveReceiver, filter);

   BroadcastReceiver pkgRemoveReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        // do my stuff
        if (Intent.ACTION_PACKAGE_REMOVED.equals(action)) {
             Toast.makeText(context, "ACTION_PACKAGE_REMOVED", Toast.LENGTH_LONG).show();
           }
    }
};