您的位置:首页 > 移动开发 > Android开发

在android收件箱中创建一条短信

2013-03-20 16:53 387 查看
 

 

    public void recordSMSInDataBase(String phonenumber,String msg,Context context) {

      ContentValues values = new ContentValues();

      values.put("address",phonenumber);//user's phone number

      values.put("type", "1");

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

      values.put("body",msg);

     

      Date now = new Date(System.currentTimeMillis());

      DateFormat d1 = DateFormat.getDateTimeInstance(DateFormat.LONG,DateFormat.LONG); //默认语言(汉语)下的默认风格(MEDIUM风格,比如:2008-6-16 20:54:53)

      String str1 = d1.format(now);

      values.put("date", str1);  //date

      Log.i("xxx", "time = "+str1);

      Uri uri = context.getContentResolver().insert(

                              Uri.parse("content://sms/outbox"), values); //写入

      Log.i("xxx", "欧了!~");

     

 }

 

数据库中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

locked    

android手机中

收件箱发件人 显示的规则是:如果联系人列表里没有,显示电话号!如果联系列表里有,就显示联系人!

不会联系人,电话一起显示的。

 

最后加入权限

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

 <uses-permission android:name="android.permission.WRITE_SMS"/>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  收件箱 写入短息