Sending SMS programatically doesn't save it to Sent Items

冷暖自知 提交于 2020-01-06 08:43:50

问题


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



来源:https://stackoverflow.com/questions/7677124/sending-sms-programatically-doesnt-save-it-to-sent-items

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!