0

我有我的接收者代码

    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);

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

谢谢!拉胡尔。

4

1 回答 1

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();
           }
    }
};
于 2012-08-29T16:42:05.283 回答