Android -- 仅适用于 whatsapp 和短信的意图选择器

Android -- intent chooser for whatsapp and sms only

我想创建一个 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 共享。我该怎么做?

将此用于 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();
            }

这是 SMS .

         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

重复