Home » Android » Perform a task on uninstall in android

Perform a task on uninstall in android

Posted by: admin April 23, 2020 Leave a comment

Questions:

I have developed an Android app.
Now I want to perform a few operations (i. e. – Reset the settings etc.. ) at the moment the app gets uninstalled from the phone.

Is it possible to reigster a listener or a function that is called at the moment the app is removed?

How to&Answers:

Sadly android at the moment does not give you a possibility to perform code at the moment your app is uninstalled.

All the settings that are set via the SharedPreferences are deleted together with everything in the Application Data an Cache folder.

The only thing that will persist is the data that is written to the SD-Card and any changes to phone settings that are made. I don’t know what happens to data that is synchronized to the contacts through your app.

Answer:

You cannot get control when your application is uninstalled — sorry!

Answer:

Since API level 8 you may use Context.getExternalFilesDir(). In theory any data placed here will be removed when the application is uninstalled.

http://developer.android.com/reference/android/content/Context.html#getExternalFilesDir(java.lang.String)

Answer:

When user uninstall android application in his mobile the PACKAGE_REMOVED receiver will call. You can get uninstalled app package name use intent,getDataString()

if (intent.getAction (). equals ("android.intent.action.PACKAGE_REMOVED")) {
          String packageName = intent.getDataString ();
          System.out.println ("uninstall:" + packageName + "package name of the program");  
}

See complete example in this link.
http://foryouneed.blogspot.in/2014/08/android-listener-application-to-install.html