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.
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.
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With