Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/206.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android——仅适用于whatsapp和sms的意向选择器_Android_Sms_Whatsapp_Android Intent Chooser - Fatal编程技术网

Android——仅适用于whatsapp和sms的意向选择器

Android——仅适用于whatsapp和sms的意向选择器,android,sms,whatsapp,android-intent-chooser,Android,Sms,Whatsapp,Android Intent Chooser,我想创建一个IntentChooser,它只提供通过SMS或WhatsApp共享文本 以下是我要通过WhatsApp共享的代码: Intent localIntent = new Intent(Intent.ACTION_SEND); localIntent.setType("text/plain"); localIntent.setPackage("com.whatsapp"); if (localIntent != null) { localI

我想创建一个
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"); 
}

我需要添加到这个也与短信共享。我怎么做呢?

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


可能重复

也许我没有很好地解释自己。我想要相同的
Intent
提供这两个选项。只需全局声明Intent并同时用于这两个选项,而不是
newintent()
。明白了吗?不,我希望
IntentChooser
只向用户提供SMS和WhatsApp。在同一时间。通过这个过程,它可以帮助您更好地使用警报对话框创建自己的选择器。工作不多。