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.
Related
I'm trying to send a SMS from mobile to another mobile.
The SMS contains a ftp link.
For example, I want to send the following link: ftp://ftp.example.com.
When the user will open the SMS, the link will be like that ftp://ftp.example.com in the message body.
When the user click this link, the chrome browser will show with the link : http://ftp.example.com
Thank's, Idan
If you are using android Built-in SMS app to send the message, then your code be like this-
String smsBody = "ftp://ftp.example.com";
String phNumber = "123456";
Intent smsIntent = new Intent(android.content.Intent.ACTION_VIEW);
smsIntent.setType("vnd.android-dir/mms-sms");
smsIntent.putExtra("address",phNumber); //optional, in case you want a default phone number
smsIntent.putExtra("sms_body",smsBody);
startActivity(smsIntent);
If you are using the SmsManager to send message, then the code be like this-
String smsBody = "ftp://ftp.example.com";
String phNumber = "123456";
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phNumber, null, smsBody, null, null);
And don't forget to give the SEND_SMS permission for both.
<uses-permission android:name="android.permission.SEND_SMS" />
Hope this will help you.
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);
I have made a program, in which I am sending some text to pre defined contact number, but now I also want to send voice message to that number please let me know how can I do this?
To send text SMS I am using below code:-
String phoneNumber = "XXXX9";
String message = editLocation.getText().toString();
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNumber, null, message, null, null);
Toast.makeText(getApplicationContext(),
"Message Sent!", Toast.LENGTH_LONG).show();
Refer this link. In this link there is an explaination on how to send images via MMS. you can just replace the image file with the Audio File. you can find the code to send voice message in the Comments of the above link.
Try something like this
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra("sms_body", "some text");
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(url)); // url would point to mp3 file
sendIntent.setType("audio/mp3");
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