Reputation: 653
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.
Upvotes: 5
Views: 8743
Reputation: 150
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
Upvotes: 0
Reputation: 116382
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"
Upvotes: 4
Reputation: 14274
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.
Upvotes: 5