How to save SMS to inbox in android?

Senthil picture Senthil · Mar 13, 2009 · Viewed 44.2k times · Source

I have written the below code for sending SMS messages.

SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(destAddr, null, mMessageText, il, null);

But this is not updating in my Inbox, I need to save the same message in Inbox, Or is there any way to invoke a native SMS application to send SMS ?

Answer

Josef Pfleger picture Josef Pfleger · May 16, 2009

You can use the sms content provider to read and write sms messages:

ContentValues values = new ContentValues();
values.put("address", "123456789");
values.put("body", "foo bar");
getContentResolver().insert(Uri.parse("content://sms/sent"), values);

I don't know why you would want to write a message you send to the inbox but if that is what you want just change the above uri to "content://sms/inbox".

Alternatively you can hand over to a messaging application by starting an activity with an intent similar to the following:

Intent sendIntent = new Intent(Intent.ACTION_SENDTO, Uri.parse("sms://"));
sendIntent.putExtra("address", "123456789");
sendIntent.putExtra("sms_body", "foo bar");
startActivity(sendIntent);

Edit: However, the sms:// content provider is not part of the SDK so I strongly recommend not using code like this in public applications for several reasons.