Sending SMS programatically doesn't save it to

2019-09-17 04:12发布

问题:

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?

回答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" />


回答2:

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