0

I am sending an SMS programmatically from my app. The sent message is not saved in Sent Items folder. I have read few posts, especially this one...

http://android-developers.blogspot.com/2010/05/be-careful-with-content-providers.html

But I do need to save it in Sent Items as I have indeed sent an SMS. What is the best way to do it such a way that my app doesn't break?

fredley
  • 32,953
  • 42
  • 145
  • 236
user835791
  • 177
  • 1
  • 13

2 Answers2

1

You can save Message Pragmatically, in sent items or in inbox.

public boolean restoreSms(Sms obj) {
    boolean ret = false;
    try {
        ContentValues values = new ContentValues();
        values.put("address", obj.getAddress());
        values.put("body", obj.getMsg());
        values.put("read", obj.getReadState());
        values.put("date", obj.getTime());
        mActivity.getContentResolver().insert(

                    Uri.parse("content://sms/sent", values);
                    //Uri.parse("content://sms/inbox", values);
        ret = true;
    } catch (Exception ex) {
        ret = false;
    }
    return ret;
}

Use this permission in AndroidManifest

<uses-permission android:name="android.permission.WRITE_SMS" />
Atif Mahmood
  • 8,882
  • 2
  • 41
  • 44
-1

Use the builtin sms app for sending the sms, have a look at this post with a code snippet how to do this: launch sms application with an intent

Community
  • 1
  • 1
HefferWolf
  • 3,894
  • 1
  • 23
  • 29