java - Android:BroadcastReceiver:UNINSTALL_PACKAGE Intent

标签 java android uninstallation broadcast

我需要检测我的应用程序何时被卸载。为此,我看到 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/

相关文章:

macos - 从 Mac OSX Lion 完全卸载 PostgreSQL 9.0.4?

CMake 支持 "make uninstall"吗?

java - 如何为空值注册 Spring 转换器?

java - 无法通过 getAttribute 获取 'index' 节点详细信息

java - 将 excel 包含在可执行 .jar 文件中

android - 在 Android 的外部存储中创建目录失败

android - 在每个 Activity 中进行 Flurry 分析?

Java - 分配节点的问题

android - 从待定意向打开特定选项卡

installation - 使用什么来创建快速而轻松的设置文件?