Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know that an app is going to be uninstalled in android?

I want to implement something like AppLock application is doing.
If in its settings it is set to lock applications uninstall/install, then while uninstalling any app (precisely on clicking the Uninstall button) a lock screen comes which asks for a password/pattern.
Only after entering the password user is allowed to uninstall the app.

What's that intent(or anything, I assume it to be an intent but not sure) that one get when Uninstall button is clicked?

Also I dont want to make it device admin, as the app I mentioned does require to be device admin.
If they can do it, then there is some way. Please help.

like image 582
akkilis Avatar asked Mar 15 '13 12:03

akkilis


1 Answers

I have found a way.

  1. When you go to Settings -> Manage Apps -> Click on any app.
    you get a broadcast with name of the package in extras.

  2. When you click on the Uninstall button on that screen, an activity is opened always name com.android.uninstaller.UnistallerActivity.

So the solution to this problem is a combined way of 1 and 2 steps mentioned above.

When ever you get the intent mentioned in first step and the extras contain the package name of your app start an activity watcher using PackageManager by which you get the top most visible activity and its package.
So now if uninstaller activity is launched then you can be sure that user wants to uninstall your app.

There after you can do necessary action to stop him to do that.

like image 66
akkilis Avatar answered Oct 02 '22 11:10

akkilis