This question already has answers here:
How can an app detect that it's going to be uninstalled? [duplicate]
(4 answers)
Closed 7 years ago.
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?
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.
You cannot get control when your application is uninstalled -- sorry!
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)
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
Related
I am working on app locker to show lock on selected apps by getting top applications's package name. For this purpose I'm calling the method in my service every 1 second to check which application is on top. I have implemented the answers given in these links https://stackoverflow.com/a/28066580/13005440 , https://stackoverflow.com/a/38829083/13005440. Its not working properly in my pixel 2 (Android 10) device. The above methods return correct package name for some apps like youtube when it opens first time / after minimize but not for other apps like messages, playstore etc. I want to implement my app lock on app minimize.
Note: When applications (messages, playstore etc) open 1st time it returns correct package name, but when that application goes to background by minimize then re-open app the method will not return its package name.
I have searched a lot but didn't find any way that will work on android 10 properly
As someone pointed out in the thread you got your solution from, are you giving the right permissions?
You need this one:
<uses-permission android:name="android.permission.PACKAGE_USAGE_STATS"/>
I would like to know which users have uninstalled my application so that I can ask them for a feedback to improve the app. Hence, I would like to detect when the user has initiated the uninstallation process on my app.
One of the older solutions on StackOverflow had the following steps:
List< ActivityManager.RunningTaskInfo > taskInfo = am.getRunningTasks(MAX_PRIORITY);
String activityName = taskInfo.get(0).topActivity.getClassName();
if (activityName.equals("com.android.packageinstaller.UninstallerActivity")) {
// do whatever is needed
Since Lollipop, getRunningTasks has been deprecated. So how can com.android.packageinstaller.UninstallerActivity activity be detected without getRunningTask?
Alternatively is there any other method to detect uninstallation process has been started on my app? Using getAppTask probably?
Apparently you wont be able to do this, you will have to rely on something called silent notification.
What we did was we sent notification every 3 days or whatever frequency you want.
On the client side as soon as a notification is received we hit a network call which mark NotificationReceived for the client. Now since notification are not full proof we assumed a threshold of 2/3 missed notification as uninstall event. And for the client we have this counter above decided threshold we contacted them for feedback.
Also no one will be willing to fill your form at the time of uninstallation as user has already decided to uninstall your application.
Read these 2 questions and answers:
native solution
GCM solution
As I know you have to mix the two. Read the limitations of first solution. You have to confirm uninstallation event of the first solution with the second solution for a complete implementation.
Hopefully, this solution will work for you. It helps you understand the reasons for your app uninstalls, reduce the uninstall rate using a powerful predictive engine and also get app Re-installs through a unique actionable channel (Android version 4.0 and above).
Just set a variable named appLastPresent for every user in the server-side and update that variable every day by calling an API using WorkManager's PeriodicWorkRequest. Also set installedDate variable when the user installs the app.
Now set up a chron job on the server side to check if the difference between installedDate and appLastPresent is greater than 7 days. Then send the user an email or message enquiring for issues or feedback, if it is greater.
NB: User can be offline for 7 days. Therefore only send email enquiring like why you are not using the app, if uninstalled please let us know why
How to check if intent or app has started ?
My use case is I am showing up notifications through my app and I want to clear them all via myBuilder.cancelAll() if default messaging app has started since my app shows sms notifications. So I am kind of looking for something like:
if (smsAppStarted) {
myBuilder.cancelAll();
}
Thanks
To check if an app has started:
Get the package name of the sms app you want to check.
Then refer to my answer here:
Android how to know an app has been started and range apps priority according the starting times
By using that code, the list taskInfo will contain the list of all apps currently running. Search that list using the package name of the sms app. If it is present in that list, it means that that app has started and currently running.
If I get you right, you need to determine, if another app is currently running. If so, then use this solution.
i am creating a simple app for a project that comes with an image and above it a button when you press the button the image becomes the wallpaper of the phone.
This i have done however for my project i need the wallpaper to be removed if the app is uninstalled how do i do this?
Save your images here this folder will be deleted when you uninstall the app
If you look at the Android Documentation for the Intent ACTION_PACKAGE_REMOVED, you will see that this broadcast action will be received by any other interested application (other apps who are registered to receive this broadcast), other than your own application.
Quote from the developer.android.com site:
Broadcast Action: An existing application package has been removed
from the device. The data contains the name of the package. The
package that is being installed does not receive this Intent.
Unfortunetaly, because your app can never detect that it is being removed, you cannot trigger a specific function that will change the Wallpaper on the device. If it were possible (which it isn't), a simple function (code follows) would have shown the Select Wallpaper chooser to the user.
Intent intent = new Intent(Intent.ACTION_SET_WALLPAPER);
startActivity(Intent.createChooser(intent, "Select Wallpaper"));
It is something the user will have to manually change once he / she has uninstalled your application.
That being said, as far as deleting all your app created files are concerned, let Android handle that for you. Use one of these options depending on the API:
API greater 8 or greater: getExternalCacheDir
API 7 or lesser: getExternalStorageDirectory.
Something like this will let you determine which one to use depending on the device API:
int currentAPIVersion = android.os.Build.VERSION.SDK_INT;
if (currentAPIVersion >= android.os.Build.VERSION_CODES.ECLAIR) {
// USE getExternalStorageDirectory
} else {
// USE getExternalCacheDir
}
This question already has answers here:
Is it possible to detect Android app uninstall?
(8 answers)
Perform a task on uninstall in android [duplicate]
(4 answers)
Closed 7 years ago.
I though it was not possible but I noticed that NQ Mobile Security is able to show a message after I click on Uninstall and before the PackageUninstaller is called.
I would like to replicate this behavior in my App.
I tried with an Activity listening to "android.intent.action.DELETE" Intent, as suggested here:
How to know my app is uninstalled from the device...?
But as I'm about to uninstall my app, the chooser pops up asking to pick my application or the package uninstaller. How can I avoid this?
Is there a different way to intercept your application UNINSTALL event? (before answering that it is not possible, please try to uninstall NQ Mobile Security and see what happens. On my Android 2.3.4 it shows a nice screen saying that is not safe to go without a security app).
I noticed that NQ Mobile Security is able to show a message after I click on Uninstall and before the PackageUninstaller is called
They must be exploiting some security flaw in Android. I will research it and see if I can get it fixed. Apps are not supposed to get control at uninstall time.
Thanks for pointing this out!
Is there a different way to intercept your application UNINSTALL event?
I sure hope not.
Opera Max is an app that does something similar - after being uninstalled opens a webpage.
How do they do this?
By using libevent, from native code, they watch /data/data/com.opera.max directory to be removed and then post good old action.VIEW broadcast when it happens.
Install their app, run it, and on rooted device from adb shell remove /data/data/com.opera.max directory
UPDATE: I created a sample app that shows how it works. BTW it doesn't work with recent (KitKat+ I think) Android versions: https://github.com/pelotasplus/ActionAfterUninstall
I'm pretty sure that they are monitoring the LogCat to intercept when the Activity Manager calls the PackageUninstaller. I think they kill the task and start their own Activity.
It's pretty clever but it's definitely exploiting a security hole in Android.
They are likely asking for a very critical permission that the user is granting them unknowingly. Look at the "Permissions" tab for this app (as of 6/15/2012): https://play.google.com/store/apps/details?id=com.nqmobile.antivirus20&hl=en.
The list of permissions this app gets is downright chilling. Among other things:
SYSTEM TOOLS RETRIEVE RUNNING APPS Allows the app to retrieve
information about currently and recently running tasks. Malicious apps
may discover private information about other apps.
CHANGE/INTERCEPT NETWORK SETTINGS AND TRAFFIC Allows the app to change network settings
and to intercept and inspect all network traffic, for example to
change the proxy and port of any APN. Malicious apps may monitor,
redirect, or modify network packets without your knowledge.
PREVENT TABLET FROM SLEEPING PREVENT PHONE FROM SLEEPING Allows the app to
prevent the tablet from going to sleep. Allows the app to prevent the
phone from going to sleep.
CHANGE YOUR UI SETTINGS Allows the app to
change the current configuration, such as the locale or overall font
size.
MODIFY GLOBAL SYSTEM SETTINGS Allows the app to modify the
system's settings data. Malicious apps may corrupt your system's
configuration.
DISPLAY SYSTEM-LEVEL ALERTS Allows the app to show
system alert windows. Malicious apps may take over the entire screen.
MOUNT AND UNMOUNT FILESYSTEMS Allows the app to mount and unmount
filesystems for removable storage.
CHANGE NETWORK CONNECTIVITY Allows
the app to change the state of network connectivity.
CHANGE WI-FI STATE Allows the app to connect to and disconnect from Wi-Fi access
points, and to make changes to configured Wi-Fi networks.
-- Update --
I also found that the Android Package Manager pretty much just deletes a package if it is asked to do so. The only check it performs prior to doing so is whether the package being deleted is currently registered as having an active device admin:
try {
if (dpm != null && dpm.packageHasActiveAdmins(packageName)) {
Slog.w(TAG, "Not removing package " + packageName + ": has active device admin");
return PackageManager.DELETE_FAILED_DEVICE_POLICY_MANAGER;
}
} catch (RemoteException e) {
}
See line 6900 in PackageManagerService in the AOSP source here.
For this, the application must be explicitly registered as a device admin by the user. See notes on device administration here: http://developer.android.com/training/enterprise/device-management-policy.html.
As per https://stackoverflow.com/a/26829978/1317564, here is some example code that does it: https://github.com/zzljob/android-uninstall-feedback/blob/master/library/jni/feedback-uninstall.c. This won't actually stop the uninstall from taking place, but does provide a way to catch it and take some action. I'm honestly surprised that this works in Android and the team may have plugged the gap in recent releases.