1 Android的SMS短消息格式和主要字段
android的sms结构和主要字段如下:
_id // 短消息序号 thread_id // 对话的序号(conversation) address // 收件人 person // 发件人 date // 日期 protocol // 协议 read // 是否阅读 status // 状态 type // 类型 reply_path_present // subject // 主题 body // 短消息内容 service_center // 服务中心
2 获取机器中的短消息
见代码,比较简单:
sms = new ArrayList<Map<String, Object>>();
Cursor c = getContentResolver().query(uriSms, null, null, null,
null);
while (c.moveToNext()) {
try {
item = new HashMap<String, Object>();
// Read the contents of the SMS;
for (int i = 0; i < c.getColumnCount(); i++) {
String strColumnName = c.getColumnName(i);
String strColumnValue = c.getString(i);
item.put(strColumnName, strColumnValue);
}
} catch (Exception e) {
Log.w("Exception:", e.getMessage());
}
sms.add(item);
3 总结
3.1 短消息
android中短消息字段比较多,但不是每个字段都是必填,根据自己实际开发需要。
3.2 发送和接收
3.2.1 发送短消息
发送短消息比较简单,API直接就有send方法。需要注意的是:短消息长度的控制,发送状态的获取。
3.2.2 接收短消息
主要思想是注册成为服务,并进行监听接收到新短消息时的系统通知,然后进行后续操作。网上代码很多,不多论述。