java - 如何在您的 Android 应用程序中使用 Intent 打开 GBWhatsApp
问题描述
我看到了这个答案How to open WhatsApp using an Intent in your Android App。但如今,人们更喜欢使用 GBWhatsapp 而不是主要的 Whatsapp。我希望我的应用程序仍然能够向两者中的任何一个发送消息(如果已安装)。如何检查 GBWhatsapp 是否已安装然后打开它,然后向特定号码发送消息?
解决方案
这是您可以用来将用户带到 GB WhatsApp 应用程序的代码。如果应用程序未安装在用户设备中,请始终使用 try and catch 方法来捕获问题。
try{
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
sendIntent.setPackage("com.gbwhatsapp");
startActivity(Intent.createChooser(sendIntent, ""));
startActivity(sendIntent);
}catch(Exception e){
e.printStackTrace();
}
推荐阅读
- angular - 嵌套子路由模块不适用于角度 9
- javascript - 登录屏幕的 document.getElementById 为 null
- reactjs - 无法使用reactjs上传文件
- svg - 如果 SVG 形状没有“填充”样式,它应该如何渲染?
- networking - 如何区分 TCP/UDP 有效负载中的协议?
- excel - 如果条件为真,将列向右移动 - excel
- python - 尽管提供了实例,ModelForm 仍在创建新记录
- vba - How to find out, if `Selection.GoTo` was successful?
- kubernetes - 如果 pod 死亡并在另一个节点上再次上升,kubernetes 的 HostPath 卷会发生什么情况?
- node.js - 在 Heroku 上部署使用 TypeScript 制作的 Node.js 服务器