我需要检测我的应用程序何时被卸载。为此,我看到 logcat 发出 UNINSTALL_PACKAGE Intent ,我只是将其添加到我现有的广播接收器中。但它只是没有捕获它,而我正在听的其他 Intent ,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
}
}
};
最佳答案
I need to detect when my app is being uninstalled
出于明显的安全原因,没有受支持的方法来执行此操作。
But it just doesn't catch it
ACTION_UNINSTALL_PACKAGE
is an activity action 。 Android 设备上的任何内容都不应该将其作为广播发送。因此,您无法通过 BroadcastReceiver
收听它。
关于java - Android:BroadcastReceiver:UNINSTALL_PACKAGE Intent ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40204006/