tags:

views:

3278

answers:

4

I have written the below code , for sending SMS .

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 ?

+6  A: 

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.

Josef
The SMS content provider is not part of the Android SDK. Your code will break on devices that replace the SMS client with their own. Your code may break in future versions of Android.
CommonsWare
@CommonsWare Good point. I added it to my answer.
Josef
A: 
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.putExtra("sms_body", "Content of the SMS goes here...");
sendIntent.setType("vnd.android-dir/mms-sms");
startActivity(sendIntent);

invoke a native SMS application with content

zhou533
A: 

hi guys,

but i would like to send sms message directly, not via native, how to do?

griffinshi
A: 

So, if you shouldn't use undocummented content providers, how should one access sms messages? And by access I mean for example reading and writing from inbox?

Cray