java - 当设备上还有 WhatsApp Business 时,如何将我的应用程序与 WhatsApp 关联?
问题描述
WhatsApp Business 代替 WhatsApp 打开。如何仅链接到 WhatsApp?这是代码:
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("https://api.whatsapp.com/send phone="+phonestr+"&text="+messagestr));
startActivity(i);
解决方案
您可以使用 设置要处理意图的目标包(应用程序 ID)Intent.setPackage
。但是,如果未安装该软件包,它将引发异常,因此请记住也要处理该异常。
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("https://api.whatsapp.com/send phone="+phonestr+"&text="+messagestr));
i.setPackage("com.whatsapp");
startActivity(i);
此外,您可以在获得ActivityNotFound
异常后尝试不同的包。例如尝试 WhatsApp,如果它抛出异常,然后尝试 WhatsApp Business 或其他
推荐阅读
- c# - System.NotImplementedException:“convert_to_eager_tensor System.Decimal”
- flutter - 如何在颤动中将小部件定位到导航栏的底部?
- r - 在R中解析txt文件
- php - 更改路线方向取决于所选语言
- javascript - 异步函数乱序执行
- python - Music21:根据频道号去除打击乐
- openssl - 使用 openssl 将 ssl 证书从 pfx 转换为 peem 的问题
- postgresql - 使用flyway迁移脚本时如何从文件中填写表格
- c# - 在 VueJS 中下载空的 pdf
- python - Plotly 渲染输出需要很长时间