Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know pre Uninstall of my application

I am using below code running background in a Service to get the pre uninstall event but it is calling for all applications, which I don't require. I want event for only my application.

Example: My application "A" Other applications "B","C"....

When tries to Uninstall "A" application I want pre uninstall event.

But current code returning pre uninstall event for other applications like "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;
            }

Thanks.

like image 270
Rajesh Gaddam Avatar asked Dec 03 '25 12:12

Rajesh Gaddam


1 Answers

In android there is no way for applications to get itself notified that app is getting uninstalled. you cant check that your application is going to uninstall.

When the user uninstalls the app, at first the process is killed, then your APK file and data directory are deleted, along with the records in Package Manager.

You can refer this link to confirm.

There's no way for your application to know that it is being uninstalled (without modifying the kernel). All files created in the data/data/your.app.package is deleted automatically upon uninstall.

Just one Alternative that I can Think of for this:

You can have another application that checks whether your first application is installed or not. If not, it can do whatever you wanted to do when App was uninstalled.

like image 146
AADProgramming Avatar answered Dec 06 '25 00:12

AADProgramming



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!