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
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 found multiple threads here about this, but none of them are working for me. This is my code:
public void sendSMS (String number, String body) {
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("smsto:" + number));
i.putExtra("abc", body);
startActivity(i);
}
It opens stock SMS app and passes the number to send, but text body is empty.
I also tried this Uri.fromParts(body, number, null) but then the app just crashes.
Replace your code with below code. You are not passing correct keys to detect number and text body for the sms.
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("sms:" + phoneNumber));
intent.putExtra("sms_body", message);
startActivity(intent);
Please read this documentation for detailed information.
Compose an SMS/MMS message with attachment
Try this
Intent smsIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("sms:" + phoneNumber));
smsIntent.putExtra("address", "12125551212");
smsIntent.putExtra("sms_body","Body of Message");
startActivity(smsIntent);
If you want to ensure that your intent is handled only by a text messaging app (and not other email or social apps), then use the ACTION_SENDTO action and include the "smsto:" data scheme. For example:
public void composeMmsMessage(String message, Uri attachment) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setData(Uri.parse("smsto:")); // This ensures only SMS apps respond
intent.putExtra("sms_body", message);
intent.putExtra(Intent.EXTRA_STREAM, attachment);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}
Is there any way to send a text message without getting a confirmation? My current code for this is:
String phoneNumber = "1234567";
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("smsto:" + phoneNumber)); // This ensures only SMS apps respond
intent.putExtra("sms_body", "TESTING TEXT MESSAGE! IT WORKS!");
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
Yes you should use SmsManager. Here is an example:
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage("phoneNo", null, "sms message", null, null);
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);