I am trying to send text messages to the selected contacts on the phone using the SmsManager but by default it sends the message using the phone GSM message option. My requirement is to show the popup to the user to choose is messaging options such as WHATSAPP, VIBER etc as shown in the image
here is my code
SmsManager sm = SmsManager.getDefault();
sm.sendTextMessage("9844598445", null, "Hello There", null, null);
Please help
Try this one
Uri uri = Uri.parse("smsto:" + smsNumber);
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
intent.putExtra("sms_body", smsText);
startActivity(intent);
What you're doing right now is directly send an SMS through the SDK. If you want to offer the user the option to send it through another installed app, you need to use an Intent:
Uri uri = Uri.parse("smsto:1234567890");
Intent it = new Intent(Intent.ACTION_SENDTO, uri);
it.putExtra("sms_body", "The SMS text");
startActivity(it);
Related
This code was working, it opens the default SMS app and message appears in textbox , ready to enter number and send, But now this code doesn't work from Above marshmallow.
but now It does not work if the default app is Messaging
Uri uri = Uri.parse("smsto:" + mphoneno);
Intent it = new Intent(Intent.ACTION_SENDTO, uri);
it.putExtra("sms_body", message);
mActivity.startActivity(it);
try below method to open default messaging app
public void sendSMS() {
String number = "12346556"; // The number on which you want to send SMS
startActivity(new Intent(Intent.ACTION_VIEW, Uri.fromParts("sms", number, null)));
}
I know since KitKat the code to start the SMS app is the following:
String default_sms_package_name = Telephony.Sms.getDefaultSmsPackage(context);
intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, body);
if (default_sms_package_name != null) intent.setPackage(default_sms_package_name);
But is there a way to preselect the SMS receiver like the SMS body?
Yes you can use ACTION_VIEW and set as many numbers as you want with address parameter as below.
Intent smsIntent = new Intent(Intent.ACTION_VIEW);
smsIntent.setData(Uri.parse("smsto:"));
smsIntent.setType("vnd.android-dir/mms-sms");
smsIntent.putExtra("address" , new String("0123456789;3393993300"));
smsIntent.putExtra("sms_body" , "Test SMS to Angilla");
startActivity(smsIntent);
I am trying to sent sms from my android app using
Uri uri = Uri.parse("smsto:"+number);
Intent it = new Intent(Intent.ACTION_SENDTO, uri);
it.putExtra("sms_body", "Here you can set the SMS text to be sent");
startActivity(it);
and it is not working when i chose jio4gvoice
Try this I hope this work
startActivity(new Intent(Intent.ACTION_VIEW, Uri.fromParts("sms", number, null)));
OR
SmsManager sm = SmsManager.getDefault();
sm.sendTextMessage(number, null, msg, null, null);
Note : for second method you need SEND_SMS permission
I'm wondering if I can send text data from my Android application to WhatsApp without showing the contacts list of WhatsApp, I just need to set the message and the mobile number internally in my Android code?
You can try something like this:
public void sendWhatsappMessageToMsisdn(String contactNumber)
{
Uri uri = Uri.parse("smsto:" + contactNumber);
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
intent.setPackage("com.whatsapp");
intent.putExtra(Intent.EXTRA_TEXT, "This is the message you want to send");
startActivity(Intent.createChooser(intent, ""));
}
This is the piece of code I am using to call the SMS application:
Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse(uri));
intent.putExtra("sms_body", body);
intent.putExtra("compose_mode", true);
launchIntent(intent);
On devices with an os version below Android 3.0, the above code is working fine, the SMS page gets opened and the message to be sent and the numbers get prefilled correctly but in Android 3.0 and above devices this is not working anymore.
In Android 3.0 the SMS intent is called and the number gets filled and not the text where as in Android 4.0 the SMS intent is called and the text gets filled and not the number.
Does anyone know the solution for this problem?
This code will works for all versions of android
String smsBody = Resources.getString("InvitationBody", getBaseContext()) + Local.User.FirstName;
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.putExtra("sms_body", smsBody);
sendIntent.setType("vnd.android-dir/mms-sms");
startActivity(sendIntent);
Following code works perfect
String body = "This is the message i need to send";
String num = "smsto:999416231";
String[] tokens = num.split(":");
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.putExtra("address",tokens[1]);
sendIntent.putExtra("sms_body", body);
sendIntent.setType("vnd.android-dir/mms-sms");
startActivity(sendIntent);
The code which i have mentioned in my question is use to pass the number as Uri.parse(uri) and its value is "smsto:9941..."
But in the new code i am splitting the text and number.