In my application I do not want to use the default message sender. For doing that I followed the following link In Android is it possible to send sms message to more than one recipient in code?
- And that code worked too. But the messages I am sending from this code are not saved on the phones outbox and inbox.
I am using sms manager like this in my code
SmsManager sms = SmsManager.getDefault(); sms.sendTextMessage(phoneNumber, null, message, null, null);
But it is not sending sms.please help me with how can i send sms in android - i have tried following too PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, new Intent( SENT), 0);
PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
new Intent(DELIVERED), 0);
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);
It's also not working.
SMSAPPActivity.java
EDIT :
btnSendSMS.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String message = txtMessage.getText().toString();
String[] PhnNoArray = new String[2];
PhnNoArray[0] = "9999999999";
PhnNoArray[1] = "8888888888";
// StringTokenizer st = new StringTokenizer(phoneNo, ",");
smsManager = SmsManager.getDefault();
for (int i = 0; i < PhnNoArray.length; i++) {
smsManager = SmsManager.getDefault();
// this is the function that does all the magic
// sms.sendTextMessage(phoneNumber, null, msg, pi, null);
smsManager.sendTextMessage(PhnNoArray[i], null, message, null,
null);
Toast.makeText(getBaseContext(), "SMS sent : " + i,
Toast.LENGTH_SHORT).show();
}
}
});
Please see the edit and tell me what i have done wrong.tost is showing up but sms is not received on other phone by using this code
In my case, it was the fact that the message body exceeded 160 characters and I had to use
sendMultipartTextMessage
in lieu ofsendTextMessage
.just send it directly... using the
SmsManager
. Only problem is that is that the user won't know of it.Hope this can help you.
MainActivity.java
add this line in AndroidManifest.xml
I used following code to send sms to multiple numbers and sent sms gets saved in messages
to send message to multiple numbers i used above function as :
If you are using dual sim device then you must have to mention the sender number, You can't pass null at that time. Otherwise, SmsManager will throw an error called
SmsManager.RESULT_ERROR_GENERIC_FAILURE
.Code to check numbers of active sims:
1) add messages in Sent instead of Outbox, as Outbox contains messages which are suppose to send or in sending state.
2) when you send message add them at the same time in "content://sms/sent uri.
what is stopping u to store them in database. and what you tried yet.
use below code to sendSMS
and by using content://sms/sent URI, you can insert the same text message into Message database