【问题标题】:How to open GBWhatsApp using an Intent in your Android App如何在您的 Android 应用程序中使用 Intent 打开 GBWhatsApp
【发布时间】:2021-08-29 03:57:54
【问题描述】:

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

【问题讨论】:

  • 这适用于任何应用程序。只需将 WhatsApp 的包名替换为 GB WhatsApp 包名即可。这会将用户带到 GB WhatsApp com.gbwhatsapp

标签: java android android-intent


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2016-11-20
    • 2019-01-29
    • 2015-06-11
    • 1970-01-01
    • 2017-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多