问题
I want to create an IntentChooser
who offer to share text only via SMS or 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");
}
I need to add to this also sharing with SMS. How can I do it?
Thank on advance.
回答1:
use this for 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();
}
and this for 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
Possibly Duplicate of Multiple IntentChooser
来源:https://stackoverflow.com/questions/38967086/android-intent-chooser-for-whatsapp-and-sms-only