呼叫广播接收器在Android的应用程序卸载时间 [英] Call broadcast receiver at time of uninstalling application in android

查看:225
本文介绍了呼叫广播接收器在Android的应用程序卸载时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想清理我的应用程序,创建时间为垃圾上卸载应用程序。

I want to clean up the junk created by my application at time on UnInstalling the Application.

使用清单文件: -

Using ManiFest File:-

补充清单文件:

 <receiver android:name="com.netdoers.com.ui.CleanReceiver" >
        <intent-filter>
            <action android:name="android.intent.action.PACKAGE_REMOVED" >
            </action>
            <data android:scheme="package"/>
        </intent-filter>
    </receiver>

创建接收器捕捉到广播事件

public class CleanReceiver extends BroadcastReceiver
{
  public void onReceive(Context context, Intent intent) {
    CustomToast.showToastMessage(context, "Uninstalling Application");
    Log.e("Uninstall", "CleanReceiver Called");
  }
} 


在Java的code: -


In Java Code:-

 BroadCastReceiver br = new CleanReceiver();
 IntentFilter intentFilter = new IntentFilter();
 intentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
 intentFilter.addDataScheme("package");
 registerReceiver(br, intentFilter);

但在卸载应用程序的时间与接收从未被称为

But at time of Uninstalling application the receiver is never been called.

Java和清单永远不会调用接收器的卸载应用程序的事件。如何在卸载应用程序的时间赶上广播事件?

推荐答案

您可以得到卸载任何其他包的广播,但从来没有为自己的包。

You can get the broadcast for any other package getting uninstalled but never for your own package.

原因

这是因为当你在你自己的应用程序卸载注册接收器和当应用被卸载时,应用程序被卸载之前注册的BroadcastReceiver已被卸载,所以其自身的卸载事件将不会通过广播接收器接收。

That happens because when you register uninstall receiver in your own app and when the app is uninstalled, the registered BroadcastReceiver has been uninstalled before the app gets uninstalled,so its own uninstallation event won't be received by that BroadcastReceiver.

只是觉得说广播注册的情况下(比如短信接收器)和应用程序即将获得uninstalled.Now短信进来广播检测,但广播的应用程序(创建它)有可能uninstalled.The导致在system.So不一致可能是这就是它发生的原因。

Just think of a scenario that say a broadcast is registered(say a sms receiver) and the app is about to get uninstalled.Now sms comes in broadcast detects it but the broadcast's application(which created it) got uninstalled.The may lead to inconsistency in the system.So may be thats the reason it happens.

这篇关于呼叫广播接收器在Android的应用程序卸载时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆