Android-仅适用于whatsapp和sms的意图选择器 [英] Android -- intent chooser for whatsapp and sms only
本文介绍了Android-仅适用于whatsapp和sms的意图选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建一个IntentChooser
,该人只提供通过SMS或WhatsApp共享文本的功能.
I want to create an IntentChooser
who offer to share text only via SMS or WhatsApp.
这是我要通过WhatsApp分享的代码:
Here is my code to share via 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共享.我该怎么办?
I need to add to this also sharing with SMS. How can I do it?
非常感谢.
推荐答案
将此用于 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)));
OR
可能重复的 查看全文