How to send a SMS to many recipients in android? I want to send a SMS to many receivers in my application. I know this code:
Uri smsToUri = Uri.parse("smsto:" + 10086);
Intent intent = new Intent(
android.content.Intent.ACTION_SENDTO, smsToUri);
String message = "hello";
// message = message.replace("%s", StoresMessage.m_storeName);
intent.putExtra("sms_body", message);
startActivity(intent);
This work for single recipient. But How to send the message to many recipients by using "ACTION_SENDTO" intent? That is too say, how to call the third-party application to send a SMS to many recipients in phone?
send sms to multiple numbers:
String strnum="10086;10086;10087;10089";
Uri smsToUri = Uri.parse("smsto:" + strnum);
or for Sending SMS to Multiple numbers using SmsManager see this post
Unable to send sms using SmsManager in Android
Related
this is going to be a newbie question, but I'm curious how Intent's ACTION_SENDTO works. The code is like this:
TextView textView = (TextView) findViewById(R.id.number_to_call);
String smsNumber = String.format("smsto: %s", textView.getText().toString());
EditText smsEditText = (EditText) findViewById(R.id.sms_message);
String sms = smsEditText.getText().toString();
Intent smsIntent = new Intent(Intent.ACTION_SENDTO);
smsIntent.setData(Uri.parse(smsNumber));
smsIntent.putExtra("sms_body", sms);
I understand that:
This is an implicit intent
ACTION_SENDTO is the action of the intent
setData takes in data of the intent
But whatever in putExtra, I guess what it does is putting in "extra" data? Immediate after running this intent, it takes me to a normal Messages app with number as smsNumber, and sms as content. My questions are:
How does the intent "know" smsNumber should be in the phone number section, and sms is in content section?
I also guess the name "sms_body" does affect the role of the data after it (aka sms is the content of message)?
Edit: I found an explanation for this. It should be in Common Intents
You can use "smsto:XXXXXXXXXX" in uri to give the phone number like in this example from the post :
ACTION_SEND used to send sms
Uri uri = Uri.parse("smsto:0800000123");
Intent it = new Intent(Intent.ACTION_SENDTO, uri);
it.putExtra("sms_body", "The SMS text");
startActivity(it);
I am trying to send a SMS through an intent, I want to add a body to the message. After user press send I want to return to the app. I've added extra as sms_body and exit_on_sent. But when I use them both the SMS appears without the body. If i don't use the exit_on_sent extra everything works fine.
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.setData(Uri.parse("smsto:" + phoneNumber));
sendIntent.putExtra("sms_body", "some text");
sendIntent.putExtra("exit_on_sent", true);
context.startActivity(sendIntent);
You could try using
startActivityForResult(sendIntent, SOME_REQUEST_CODE)
but in my experience it doesn't works most of the time.
I would recommend instead using SmsManager.
SmsManager smsMgr = SmsManager.getDefault();
if(smsMgr != null){
PendingIntent sentIntent = PendingIntent.getBroadcast(
getActivity().getApplicationContext(), 0,
new Intent(MY_ACTION_INTENT_SENT), 0);
smsMgr.sendTextMessage(phone, null, message, sentIntent, null);
}
Depending on your application you can do the rest of processing when MY_ACTION_INTENT is sent (indicating the message has actually been sent) or right after sendTextMessage(...) returns.
From API Level 19 there are some interesting features you may found useful http://developer.android.com/reference/android/provider/Telephony.html
Hope it helps.
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);
This question already has an answer here:
Sending SMS programatically not stored in outbox?
(1 answer)
Closed 9 years ago.
I using "sendTextMessage" in android SDK to send message programmatically. But the sent message doesn't show up in the outbox.
public void sendSMS() {
String phoneNumber = "0123456789";
String message = "Hello World!";
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNumber, null, message, null, null);
}
Is there any other flag for adding the message to the outbox?
The concept of "outbox" depends on the SMS application. You cannot programatically add SMS's to outboxes of SMS applications on the device (there could be more than one). If you want the SMS to be shown in the users default SMS application then use the intent ACTION_SEND to send the SMS
Code for doing it with an intent
Uri uri = Uri.parse("smsto:xxxxxxx");
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
it.putExtra("sms_body", "THE SMS BODY");
startActivity(intent);
In short, If you want to send it programatically using SMSManager It would not show in the outbox. Use intents for that.
Title is obvious. Can I send "SMS received intent" on the android phone? In other words, virtually receive custom SMS to fake some SMS receivers.
You can create fake SMS (GMS type) so built-in catch like real message. Here is my answer
Intent intent = new Intent();
intent.setClassName("com.android.mms",
"com.android.mms.transaction.SmsReceiverService");
intent.setAction("android.provider.Telephony.SMS_RECEIVED");
intent.putExtra("pdus", new Object[] { pdu });
intent.putExtra("format", "3gpp");
context.startService(intent);