通过intent打开whatsapp在android 11中不起作用

uwopmtnx  于 2021-07-12  发布在  Java
关注(0)|答案(1)|浏览(586)

有意打开whatsapp在android os 11中不起作用,但在android(os)10设备上工作正常,它会在android 11设备上显示消息“whatsapp app not installed in your phone”。有人有解决办法吗?

String contact = "+91 9999999999"; // use country code with your phone number
        String url = "https://api.whatsapp.com/send?phone=" + contact;
        try {
            PackageManager pm = context.getPackageManager();
            pm.getPackageInfo("com.whatsapp", PackageManager.GET_ACTIVITIES);
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setData(Uri.parse(url));
            context.startActivity(i);
        } catch (PackageManager.NameNotFoundException e) {
          Toast.makeText(mContext, "Whatsapp app not installed in your phone",Toast.LENGTH_LONG).show();
           e.printStackTrace();
        }
j8yoct9x

j8yoct9x1#

android 11在软件包可见性方面有新的变化。
您需要向应用程序清单中添加一个新分区:

<queries>
    <package android:name="com.whatsapp" />
</queries>

您可以在文档中找到更多信息:https://developer.android.com/training/basics/intents/package-visibility

相关问题