天天看点

android sms(短信)详解

  相关的协议:

content://sms/inbox       收件箱

content://sms/sent       已发送

content://sms/draft       草稿

content://sms/outbox       发件箱

content://sms/failed       发送失败

content://sms/queued       待发送列表

sms相关的字段如下:

_id              一个自增字段,从1开始

thread_id   序号,同一发信人的id相同

address     发件人手机号码

person       联系人列表里的序号,陌生人为null

date           发件日期

protocol     协议,分为: 0 SMS_RPOTO, 1 MMS_PROTO 

read          是否阅读 0未读, 1已读 

status        状态 -1接收,0 complete, 64 pending, 128 failed

type

   ALL    =0;

   INBOX  = 1;

   SENT   = 2;

   DRAFT  = 3;

    OUTBOX =4;

    FAILED =5;

    QUEUED =6;

body                    短信内容

service_center    短信服务中心号码编号

subject                 短信的主题

reply_path_present    TP-Reply-Path

删除短信:

getContentResolver().delete(Uri.parse("content://sms"), "_id=?",new String[]{"3"});

getContentResolver().delete(Uri.parse("content://sms/conversations/3"),"_id=?", new String[]{"5"}); 

修改短信:

ContentValues cv = newContentValues();   

cv.put("thread_id","2");   

cv.put("address","00000");   

cv.put("person","11");   

cv.put("date","11111111");   

this.getContentResolver().update(Uri.parse("content://sms/inbox/4"),cv, null,null);   

插入短信:

ContentValues cv = newContentValues();   

cv.put("_id","99");   

cv.put("thread_id","0");   

cv.put("address","9999");   

cv.put("person","888");   

cv.put("date", "9999");

cv.put("protocol", "0");

cv.put("read", "1");

cv.put("status", "-1");

//cv.put("type", "0");

cv.put("body", "@@@@@@@@@");

this.getContentResolver().insert(Uri.parse("content://sms/failed"),cv);