gpt4 book ai didi

java - 通过 Intent 打开whatsapp在Android 11中不起作用

转载 作者:行者123 更新时间:2023-12-03 23:59:06 25 4
gpt4 key购买 nike

有意打开 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();
}

最佳答案

package visibility的android 11有新变化.
您需要添加一个新部分 queries在你的应用程序下<manifest>带有所需包名称的标签:

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

关于java - 通过 Intent 打开whatsapp在Android 11中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64872147/

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