【问题标题】:Android -- intent chooser for whatsapp and sms onlyAndroid -- 仅适用于 whatsapp 和短信的意图选择器
【发布时间】:2016-12-22 08:49:06
【问题描述】:

我想创建一个IntentChooser,只提供通过 SMS 或 WhatsApp 分享文本。

这是我通过 WhatsApp 分享的代码:

Intent localIntent = new Intent(Intent.ACTION_SEND);
localIntent.setType("text/plain");
localIntent.setPackage("com.whatsapp");
if (localIntent != null) {
    localIntent.putExtra(Intent.EXTRA_TEXT, "Hi there! I'm using this app");
    startActivity(Intent.createChooser(localIntent, "Hi there! I'm using this app"); 
}

我需要添加到此还与 SMS 共享。我该怎么做?

【问题讨论】:

  • 您最好使用警报对话框制作自己的选择器。工作量不大。

标签: android sms whatsapp android-intent-chooser


【解决方案1】:

将此用于 Whatsapp

            try {
                startActivity(new Intent(Intent.ACTION_SEND).setType("text/plain").setPackage("com.whatsapp").putExtra(Intent.EXTRA_TEXT, Message));
            } catch (android.content.ActivityNotFoundException ex) {
                Toast.makeText(this, "Whatsapp have not been installed.", Toast.LENGTH_SHORT).show();
            }

这适用于短信

         String number = "12346556";  // The number on which you want to send SMS  
         startActivity(new Intent(Intent.ACTION_VIEW, Uri.fromParts("sms", number, null)));

可能与Multiple IntentChooser 重复

【讨论】:

  • 也许我没有很好地解释自己。我想要同样的Intent 提供这两个选项。
  • 只需在全局范围内声明意图并同时使用两者,而不是 new Intent()。收到了吗??
  • 不,我希望 IntentChooser 仅向用户提供 SMS 和 WhatsApp。同时。
  • 通过这个它可以帮助你stackoverflow.com/a/18068122/5305430
猜你喜欢
  • 2019-03-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-23
  • 1970-01-01
  • 1970-01-01
  • 2018-08-25
  • 1970-01-01
相关资源
最近更新 更多