【问题标题】:How to know pre Uninstall of my application如何知道我的应用程序的预卸载
【发布时间】:2015-03-21 01:01:55
【问题描述】:

我在服务中使用下面的代码运行后台来获取预卸载事件,但它正在调用我不需要的所有应用程序。我只想要我的应用程序的事件。

示例: 我的应用程序“A” 其他应用程序“B”、“C”....

当尝试卸载“A”应用程序时,我想要预卸载事件。

但当前代码为“B”、“C”等其他应用程序返回预卸载事件.....

            // get the info from the currently running task
            List<ActivityManager.RunningTaskInfo> taskInfo = mActivityManager
                    .getRunningTasks(10);

            String activityName = taskInfo.get(0).topActivity
                    .getClassName();

            Log.d("topActivity", "CURRENT Activity ::" + activityName);

            if (activityName
                    .equals("com.android.packageinstaller.UninstallerActivity")) {
                // User has clicked on the Uninstall button under the Manage
                // Apps settings

                // do whatever pre-uninstallation task you want to perform

                Toast.makeText(getApplicationContext(),
                        "warning!!! You are not supposed to uninstall",
                        Toast.LENGTH_SHORT).show();
                if (!mIntimation) {
                    startIntimate();
                    mIntimation = true;
                }
            } else {
                mIntimation = false;
            }

谢谢。

【问题讨论】:

  • 你不能,不是为了你自己。如果您可以自行卸载,那将是恶意软件的宝库。

标签: android performance android-intent android-activity


【解决方案1】:

【讨论】:

  • 这将在应用程序被删除后收到。它不会解决我的问题.....
【解决方案2】:

在 android 中,应用程序无法自行通知应用程序正在卸载。您无法检查您的应用程序是否要卸载。

当用户卸载应用程序时,首先进程被杀死,然后你的APK文件和数据目录被删除,以及包管理器中的记录。

你可以参考这个link来确认。

您的应用程序无法知道它正在被卸载(无需修改内核)。卸载时会自动删除 data/data/your.app.package 中创建的所有文件。

我能想到的只是一个替代方案:

您可以使用另一个应用程序来检查您的第一个应用程序是否已安装。如果没有,它可以在卸载 App 时做任何你想做的事情。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-18
    相关资源
    最近更新 更多