如何获得动作的默认应用程序 [英] How to get default application for an action

查看:52
本文介绍了如何获得动作的默认应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何确定某个应用程序的默认应用程序是哪个应用程序?例如,我想知道哪个应用程序用于拨打电话或接收短信.有没有办法找出以编程方式将哪个应用程序设置为默认应用程序?

How can I determine which application is the default application for a certain action? For example I want to know which application is used for making calls or receiving text messages. Is there any way to find out which application is set as default programmatically?

推荐答案

resolveActivity does something along the lines of what you're looking for. From the official docs:

确定针对给定Intent执行的最佳操作.这就是resolveActivity(PackageManager)在没有类的情况下查找活动已明确指定.

Determine the best action to perform for a given Intent. This is how resolveActivity(PackageManager) finds an activity if a class has not been explicitly specified.

这是一个示例:

Intent i = (new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.google.com"));
PackageManager pm = context.getPackageManager();
final ResolveInfo mInfo = pm.resolveActivity(i, 0);
Toast.makeText(
    context, 
    pm.getApplicationLabel(mInfo.activityInfo.applicationInfo),
    Toast.LENGTH_LONG
).show();

请注意,返回值有些模糊:

Note that the return value is somewhat fuzzy:

返回一个ResolveInfo,其中包含最终的活动意图决心是最好的行动.如果没有匹配的活动,则返回null被找到.如果找到多个匹配活动,则没有默认设置,返回包含其他内容的ResolveInfo,例如活动解析器.

Returns a ResolveInfo containing the final activity intent that was determined to be the best action. Returns null if no matching activity was found. If multiple matching activities are found and there is no default set, returns a ResolveInfo containing something else, such as the activity resolver.

这篇关于如何获得动作的默认应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆