From my Application I am trying to uninstalling an application by using the code
Intent uninstallIntent = new Intent(Intent.ACTION_DELETE);
uninstallIntent.setData(Uri.parse("package:" +packageName));
uninstallIntent.setAction(Intent.ACTION_VIEW);
startActivityForResult(uninstallIntent,UNINSTALL_APPLICATION);
as per I am starting the activity for result I want to perform different actions on the basis of user’s input like if cancelled or clicked on ok.
As I expected the result code of clicking ok will be RESULT_OK and clicking on cancel will be RESULT_CANCEL, but in actual in both cases I am getting RESULT_CANCEL.
So how can I differentiate the user’s input.
Thanks!
After a lot of thoughts in mind finally i have got the solution tricky one.
How I Implemented at the time of calling the Uninstall Intent i have saved the package name in a preferences file by using
And what i have done in OnActivityresult i have just checked whether the application with saved package name still present if it is means user has clicked on Cancel else he clicked Ok.
Code for Checking the application presence
Thanks.
UPDATED:
As platform changed a lot since I answered this here is the update
Now you can use an intent where you can explicitly define whether it should return a result or not
Documentation : https://developer.android.com/reference/android/content/Intent.html#ACTION_UNINSTALL_PACKAGE
This will return a result a
From the documentation :
Starting API 21 Android added a helper method
Read more about the changes in the link below, stating from Android Q the above updated approach is also deprecated.
https://developer.android.com/reference/android/content/pm/PackageInstaller.html#uninstall(java.lang.String,%20android.content.IntentSender)