navid abutorab navid abutorab - 2 months ago 16
Android Question

android -how to save sent messages sent via SmsMessage

I'm using SmsMessage to send sms via my application . this is my code :

SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(tel, null, text, null, null);


it works fine and I've no problem with sending messages. the only issue is that I want to save sent sms in android message inbox.

How can I do so ?

Answer

Sms content provider can help you to write data into message inbox:

    ContentValues values = new ContentValues();
    values.put("address", tel);
    values.put("body", text);
    values.put("date", "135123000000");
    getContentResolver().insert(Uri.parse("content://sms/sent"), values);

Permission required:

 <uses-permission android:name="android.permission.WRITE_SMS"/>
<uses-permission android:name="android.permission.READ_SMS"/>