Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
234 views
in Technique[技术] by (71.8m points)

How to save SMS to inbox in android?

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 ?

question from:https://stackoverflow.com/questions/642076/how-to-save-sms-to-inbox-in-android

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...