user861973
user861973

Reputation: 777

Clear Default Android Application

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 action of Call_privilaged. but user has set inbuilt dialer as default launcher for Call_privilaged action.

My question is can I know pro grammatically that user has set dialer as default launcher for Call_privalged action.

Thank You.

Upvotes: 1

Views: 450

Answers (2)

Adam Nybäck
Adam Nybäck

Reputation: 855

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.

Upvotes: 0

CommonsWare
CommonsWare

Reputation: 1006674

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.

Upvotes: 1

Related Questions