When you use Intent.ACTION_DELETE, how can you tell if the user actually uninstalls the app?
Asked Answered
P

3

5

This is my code

Intent intent = new Intent(Intent.ACTION_DELETE);
intent.setData(Uri.parse("package:" + theApp.getAppOpen()));
startActivity(intent);

When startActivity is called, a default prompt comes up, asking the user whether they want to uninstall that app.

How can I tell if the user says "ok" to uninstall the app? Assume my app is not the one being uninstalled.

Proven answered 15/5, 2014 at 23:37 Comment(0)
E
5

You have two options, and you might want to use a combination of the two:

1) Register a BroadcastReceiver for ACTION_PACKAGE_REMOVED, and once fired, you can inspect the data of the intent to see whether your package was removed. It might be wise to add a time-out of sorts, possibly through an Alarm set five minutes into the future.

2) Once the user returns from either uninstalling or canceling the uninstall, your Activity will resume. You can check whether the package of interest still exists in onResume(), using PackageManager.getPackageInfo() or similar. Note: The user might not return to your app, in which case the time-out/Alarm recommendation would become important.

Enlace answered 16/5, 2014 at 4:20 Comment(2)
Ah. Thank you. The second way was what I was interested in. But, what do you mean by the "time-out/Alarm recommendation"?Modification
I was referring to the last line in the first option -- setting an Alarm five minutes into the future to check whether an app was actually uninstalled -- since you may not see the resume for a while if the user doesn't return; or you may not see it at all.Enlace
L
4

I think you can use the "ACTION_UNINSTALL_PACKAGE" intent (API 14 and above) so that you could check if the uninstallation has succeeded or not.

docs say:

Activity Action: Launch application uninstaller.

Input: The data must be a package: URI whose scheme specific part is the package name of the current installed package to be uninstalled. You can optionally supply EXTRA_RETURN_RESULT.

Output: If EXTRA_RETURN_RESULT, returns whether the install succeeded.

Constant Value: "android.intent.action.UNINSTALL_PACKAGE"

Lunna answered 1/3, 2015 at 0:37 Comment(1)
Best for me but requires permission: android.permission.REQUEST_DELETE_PACKAGESSuperpose
D
0

It might be late but you can use startActivityForResult(removeIntent, 0) as a first step and then after taking any action - whether it's uninstalled or not - onActivityResult method is called, so, for a second step you can check in onActivityResult whether this app now exists or not. Follow this for more details of the second step: [Check if application is installed - Android

Dorita answered 21/4, 2020 at 21:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.