Can we know that user has set default application for particular action? i. e. android.intent.action.CALL_PRIVILEGED
Suppose I my application also provide called on act
Can we know that user has set default application for particular action? i. e. android.intent.action.CALL_PRIVILEGED
I do not think that there is an easy way to do this. Calling getPreferredActivities()
on PackageManager
, and sifting through the List<IntentFilter>
you get back to try to find a match for your Intent
might work.
You can use resolveActivity()
of Intent or PackageManager.
Intent intent = ...
ComponentName componentName = intent.resolveActivity(getPackageManager());
if (componentName.getPackageName().equals("android")) {
// No default selected
...
} else if (componentName.getPackageName().equals(getPackageName())) {
// We are default
...
} else {
// Someone else is default
...
}
If you don't handle the intent yourself you could also need a null check for the case where there is no app able to handle the intent.
Not sure if this works on all devices and all versions of Android. Tested on Android 4.1-4.3 on Nexus devices.