-1

How to start an Activity ,Service or broadcast receiver before an application uninstalled by the user who has earlier installed the app on his/her device?

If possible please help me? and thanks in advance

Chetan Patil
  • 462
  • 1
  • 5
  • 22

4 Answers4

5

No dear 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 that tell other apps which intent filters you've registered for.

But you can create your folder in your cache dir so that when your application will be deleted all folders and files automatically will be deleted.

Please check it. http://developer.android.com/guide/topics/data/data-storage.html

So 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.

Another approach could be to have another application that checks whether this application is installed or not. If not, it can do the clean-up work.

like this

Maveňツ
  • 9,147
  • 14
  • 53
  • 94
  • 1
    @maveň : You are right, But today I uninstalled **Truecaller** from my which opens a link in the default browser for knowing about the reason for uninstall. Any one have idea, how this is done. I think there is no presence of another app to notify if the truecaller is uninstalled or not. – Yksh Aug 02 '16 at 11:00
3

You can't detect for your app whether it has installed or uninstalled but for other apps you can get this detail using this BroadcastReceiver.

<receiver android:name=".UninstallApkReceiver">
    <intent-filter>
        <action android:name="android.intent.action.PACKAGE_REMOVED"/>
    </intent-filter>
</receiver>
N Sharma
  • 31,202
  • 88
  • 240
  • 427
1

YES using Accessibility Service you can detect Uninstall event and then read rhe screen to find app name. Voodo app uses this concept.

Dhruv
  • 11
  • 1
  • I just tested this an confirmed it works in Android 7.1.1. You can try out the app here: https://play.google.com/store/apps/details?id=com.voodoo.android – Sam Apr 30 '17 at 04:32
  • Hi, Dhruv. Happy Diwali!! If you are aware of the Quora app, when I delete the app, it shows my account has been deactivated. Any idea how to do it? – Therii Nov 04 '21 at 17:39
-1

Yes you can create a broadcast receiver for package add/remove and start a service from it.

register your broadcast in manifest file as like this

    <receiver android:name=".YourReceiver">
    <intent-filter>
        <action android:name="android.intent.action.PACKAGE_INSTALL" />
        <action android:name="android.intent.action.PACKAGE_ADDED" />
        <data android:scheme="package"/>
    </intent-filter>
   </receiver> 

or you can register it via java code

 IntentFilter intentFilter = new IntentFilter();
 intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
  intentFilter.addAction(Intent.ACTION_PACKAGE_INSTALL);
  intentFilter.addDataScheme("package");
 registerReceiver(br, intentFilter);

hope this answer is helpful to you friend :)

Prince Thomas
  • 990
  • 7
  • 10