gpt4 book ai didi

android - 如何获取操作的默认应用程序

转载 作者:搜寻专家 更新时间:2023-11-01 07:59:30 25 4
gpt4 key购买 nike

如何确定哪个应用程序是特定操作的默认应用程序?例如,我想知道哪个应用程序用于调用电话或接收短信。有什么方法可以通过编程找出哪个应用程序被设置为默认应用程序?

最佳答案

PackageManager.resolveActivity按照您要查找的内容执行某些操作。来自官方文档:

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

这是一个 example :

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();

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

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

关于android - 如何获取操作的默认应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23172185/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com