我需要检测我的应用程序何时被卸载。为此,我看到logcat发送了UNINSTALL_PACKAGE意图,我只是将它添加到现有的广播接收器中。但它只是没有抓住它,而我正在听的其他意图,TIME_TICK,工作得很好。为什么?
目前使用的代码:
private IntentFilter intentFilter;
static {
intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_TIME_TICK);
intentFilter.addAction(Intent.ACTION_UNINSTALL_PACKAGE);
}
private final BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
if (action.equals(Intent.ACTION_UNINSTALL_PACKAGE) {
Log.e("App", "Uninstalling");
} else if (action.equals(Intent.ACTION_TIME_TICK){
// this works
}
}
};发布于 2016-10-23 14:30:49
我需要检测我的应用程序何时被卸载。
出于明显的安全原因,没有支持的方法来做到这一点。
但它就是抓不到它
is an activity action。Android设备上的任何东西都不应该作为广播发送。因此,您不能通过BroadcastReceiver收听它。
发布于 2016-10-23 14:37:02
我见过logcat发送UNINSTALL_PACKAGE意图,我只是把它添加到我现有的广播接收者中。但是它没有捕捉到它,而我正在听的其他意图,TIME_TICK,工作得很好。为什么?
每当您的应用程序被卸载时,Android就会杀死与该应用程序相关的所有组件以及空闲内存和资源。Uninstall广播接收器的意图是监听卸载事件的其他应用,而不是你的应用程序。
如果您想要捕获应用程序的uninstall事件,那么google没有提供任何概念,但是您可以通过观察您的文件系统中的数据更改来实现,在那里您需要继续监视文件系统中的更改。
这种解决方案并不适用于所有手机& Android的不同版本。
发布于 2018-07-18 00:49:28
当您使用android.intent.action.PACKAGE_REMOVED或ACTION_UNINSTALL_PACKAGE卸载时,您就不能用IntentFilter监听ACTION_DELETE吗?
https://stackoverflow.com/questions/40204006
复制相似问题