简体   繁体   中英

Clear Default Android Application

Can we know that user has set default application for particular action? ie 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.

Can we know that user has set default application for particular action? ie 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM