Android的SMS短消息格式和主要字段

android的sms结构和主要字段如下:
其他代码 复制代码
  1. _id                 // 短消息序号   
  2. thread_id           // 对话的序号(conversation)   
  3. address             // 收件人   
  4. person              // 发件人   
  5. date                // 日期   
  6. protocol            // 协议   
  7. read                // 是否阅读   
  8. status              // 状态   
  9. type                // 类型   
  10. reply_path_present  //    
  11. subject             // 主题   
  12. body                // 短消息内容   
  13. service_center      // 服务中心  

 2 获取机器中的短消息

见代码,比较简单:

Java代码 复制代码
  1. sms = new ArrayList<Map<String, Object>>();   
  2. Cursor c = getContentResolver().query(uriSms, nullnullnull,   
  3.         null);   
  4. while (c.moveToNext()) {   
  5.     try {   
  6.         item = new HashMap<String, Object>();   
  7.   
  8.         // Read the contents of the SMS;   
  9.         for (int i = 0; i < c.getColumnCount(); i++) {   
  10.             String strColumnName = c.getColumnName(i);   
  11.             String strColumnValue = c.getString(i);   
  12.   
  13.             item.put(strColumnName, strColumnValue);   
  14.         }   
  15.     } catch (Exception e) {   
  16.         Log.w("Exception:", e.getMessage());   
  17.     }   
  18. sms.add(item);  

 3 总结

3.1 短消息

    android中短消息字段比较多,但不是每个字段都是必填,根据自己实际开发需要。

3.2 发送和接收

3.2.1 发送短消息
    发送短消息比较简单,API直接就有send方法。需要注意的是:短消息长度的控制,发送状态的获取。
3.2.2 接收短消息
    主要思想是注册成为服务,并进行监听接收到新短消息时的系统通知,然后进行后续操作。网上代码很多,不多论述。
原文地址:https://www.cnblogs.com/tt_mc/p/1678748.html