Android - 仅针对whatsapp和sms的意图选择器

时间:2016-08-16 05:15:47

标签: android sms whatsapp android-intent-chooser

我想创建IntentChooser提供仅通过短信或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共享。我该怎么办?

感谢提前。

1 个答案:

答案 0 :(得分: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

的可能重复