Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Intent defaults - detect and clear

Is there a way to detect that a phone has a default application chosen for an intent such as android.intent.action.SEND ?

Is there a way to clear the default application via code?

I'd like to give the user an option to remove the default or at least show a screen telling them how to do it manually, if I can detect it.

like image 646
user432209 Avatar asked Aug 29 '26 18:08

user432209


2 Answers

Take a look at PackageManager. With it, you can determine how an Intent will be handled with resolveActivity(intent). It looks like the method for clearing the preference (clearPackagePreferredActivities) only works on your own package.

like image 131
Ian G. Clifton Avatar answered Aug 31 '26 08:08

Ian G. Clifton


Use 2-step detection of defaults:

PackageManager.queryIntentActivities to get all activities for Intent, PackageManager.resolveActivity to get resolved.

If resolved one is in the list returned by queryIntentActivities, then there will be no "Complete action using" dialog, thus "default" activity was set.

like image 38
Pointer Null Avatar answered Aug 31 '26 08:08

Pointer Null



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!