Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 908
Ryan D'souza Avatar asked Jan 11 '23 14:01

Ryan D'souza


2 Answers

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.

like image 132
323go Avatar answered Jan 13 '23 03:01

323go


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"

like image 31
android developer Avatar answered Jan 13 '23 03:01

android developer