Intent Action_dial 在 android 11 中不起作用 [英] Intent Action_dial does not function in android 11

查看:127
本文介绍了Intent Action_dial 在 android 11 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一个 android 应用程序,需要一个启动电话的功能,所以我添加了这段代码.

I am currently developing an android app and needed a function that starts a phone call so I added this code.

 public void dialPhoneNumber(String phoneNumber) {
        Intent intent = new Intent(Intent.ACTION_DIAL);
            intent.setData(Uri.parse("tel:" + phoneNumber));
            if (intent.resolveActivity(getPackageManager()) != null) {
                startActivity(intent);
            }
        }

.. 它似乎在较旧的 android 版本中运行良好,但是当我在 android 11 中测试它时,它根本不起作用我尝试了 action_call 并添加了权限 <uses-权限 android:name="android.permission.CALL_PHONE";/> 仍然不起作用.

.. it seems to work perfectly in older android versions but when I test it in android 11 it doesn't function at all I tried action_call and added the permission <uses-permission android:name="android.permission.CALL_PHONE" /> still doesn't work.

推荐答案

你的问题出在代码行intent.resolveActivity(getPackageManager()).当你调用resolveActivity时,你会得到这样的警告:

Your problem lies in the line of code intent.resolveActivity(getPackageManager()). When you call resolveActivity, you will get a warning like this:

考虑在调用此方法时向清单添加声明;详情请参阅 https://g.co/dev/packagevisibility

Consider adding a declaration to your manifest when calling this method; see https://g.co/dev/packagevisibility for details

查看PackageManager下的文档,会看到这个说明:

Check the document under PackageManager, you will see this note:

注意:如果您的应用面向 Android 11(API 级别 30)或更高版本,则此类中的每个方法都会返回过滤后的应用列表.详细了解如何管理包可见性.

Note: If your app targets Android 11 (API level 30) or higher, the methods in this class each return a filtered list of apps. Learn more about how to manage package visibility.

那是什么意思?

在 android 11 中,Google 添加了包可见性策略.应用程序现在可以更严格地控​​制查看其他应用程序.您的应用程序将无法查看或访问您的应用程序之外的应用程序.

In android 11, Google added package visibility policy. Apps now have tighter control over viewing other apps. Your application will not be able to view or access applications outside of your application.

你需要做什么?

您需要做的就是在 AndroidManifest.xml 中添加以下代码行:

All you need to do is add below line of code to AndroidManifest.xml:

<manifest>
    <queries>
        <!-- Specific intents you query for -->
        <intent>
            <action android:name="android.intent.action.DIAL" />
        </intent>
    </queries>
</manifest>

更多信息:

  1. Android 11 中的包可见性
  2. Android 上的包可见性过滤

这篇关于Intent Action_dial 在 android 11 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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