首页 > 解决方案 > 如何在您的 Android 应用程序中使用 Intent 打开 GBWhatsApp

问题描述

我看到了这个答案How to open WhatsApp using an Intent in your Android App。但如今,人们更喜欢使用 GBWhatsapp 而不是主要的 Whatsapp。我希望我的应用程序仍然能够向两者中的任何一个发送消息(如果已安装)。如何检查 GBWhatsapp 是否已安装然后打开它,然后向特定号码发送消息?

标签: javaandroidandroid-intent

解决方案


这是您可以用来将用户带到 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();
}

推荐阅读