0

I am making an app and want to know when the app is uninstalling. For doing it, I used BroadcastReceiver but I don't know where is my code is wrong? (when my app is uninstalling, BroadcastReceiver can't receive any message about uninstalling) It's my app's Manifest:

<receiver android:name="receiver">
  <intent-filter>
     <action android:name="android.intent.action.PACKAGE_ADDED"/>
     <action android:name="android.intent.action.PACKAGE_DATA_CLEARED"/>
     <action android:name="android.intent.action.PACKAGE_INSTALL"/>
     <action android:name="android.intent.action.UID_REMOVED"/>    
     <action android:name="android.intent.action.PACKAGE_REMOVED"/>
     <action android:name="android.intent.action.MEDIA_REMOVED"/>
     <action android:name="android.intent.action.MEDIA_BAD_REMOVAL"/>  
     <action android:name="android.intent.action.BATTERY_OKAY"/>         
     <data android:scheme="com.example.testpermission"/>
  </intent-filter>

David M
  • 4,325
  • 2
  • 28
  • 40

2 Answers2

1

You cannot get an event when your own app is uninstalling. See here. There is also a post on the subject here.

Community
  • 1
  • 1
Warpzit
  • 27,966
  • 19
  • 103
  • 155
  • Ok,I search on the Internet ,that there are some app for parents who install an app on their children's mobile ,and when children want to unistall it ,that app ask a pass...how this apps work? – user3090559 Dec 15 '13 at 09:13
  • @user3090559 thats a very different scenario. I don't know how it has been implemeneted but the child phone would need to run a custom rom or special launcher (or something third I don't know about). – Warpzit Dec 15 '13 at 09:16
  • @Warpzit I'm pretty sure those apps would have to utilize the `Device Administration` API, which would enforce enterprise policies. http://developer.android.com/guide/topics/admin/device-admin.html – kaderud Dec 15 '13 at 09:20
  • could you give me a suggedtion to make my app safer than...I wan't make an app like system app and pre install app...what am I do? – user3090559 Dec 15 '13 at 09:21
  • @chrkad Thanks, haven't seen this before. – Warpzit Dec 15 '13 at 09:21
0

You can't, but if you have second installed application on the device - you can get notification via that application about the uninstallation of the first one (as far as I remember).

I believe that the application cannot monitor its own uninstall from two reasons:

  1. It will make it much harder to uninstall application (some evil apps might even try to do something bad when their application is being removed).
  2. If you remove application - you cannot run it, or send it events! The app should be closed for clean deletion.

About how to do it from second app: Your second app should be a receiver to the ACTION_PACKAGE_REMOVED event (read about BroadcastReceiver, and see: http://developer.android.com/reference/android/content/Intent.html#ACTION_PACKAGE_REMOVED)

Gari BN
  • 1,635
  • 2
  • 17
  • 31
  • thanks.why I can't understand that app is unistalling directly?if I want to make second app for controll my first app and protoct it,how the second app can recognize the first app is unistalling? – user3090559 Dec 15 '13 at 09:37