简体   繁体   English

清除默认的Android应用程序

[英]Clear Default Android Application

Can we know that user has set default application for particular action? 我们是否可以知道用户已为特定操作设置了默认应用程序? ie android.intent.action.CALL_PRIVILEGED 即android.intent.action.CALL_PRIVILEGED

Suppose I my application also provide called on action of Call_privilaged. 假设我的应用程序还提供了Call_privilaged上的被调用操作。 but user has set inbuilt dialer as default launcher for Call_privilaged action. 但是用户已将内置拨号程序设置为Call_privilaged操作的默认启动器。

My question is can I know pro grammatically that user has set dialer as default launcher for Call_privalged action. 我的问题是,我可以从语法上知道用户已将Dialer设置为Call_privalged操作的默认启动器。

Thank You. 谢谢。

Can we know that user has set default application for particular action? 我们是否可以知道用户已为特定操作设置了默认应用程序? ie android.intent.action.CALL_PRIVILEGED 即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. PackageManager上调用getPreferredActivities() ,并筛选List<IntentFilter>您将返回以尝试找到与您的Intent匹配的方法。

You can use resolveActivity() of Intent or PackageManager. 您可以使用Intent或PackageManager的resolveActivity()

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. 不确定这是否适用于所有设备和所有版本的Android。 Tested on Android 4.1-4.3 on Nexus devices. 在Nexus设备上的Android 4.1-4.3上进行了测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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