androidの读取短信内容 1. 读取短信内容,很简单,直接上代码
<span style="font-size:14px;">    public Uri SMS_INBOX = Uri.parse("content://sms/inbox");    private void fillListView() {    ListView view = (ListView) findViewById(R.id.sms_list);    ArrayList<HashMap<String, String>> list = readAllSMS();    SimpleAdapter listItemAdapter = new SimpleAdapter(this, list,                    android.R.layout.simple_list_item_2,                 new String[] {"addr","body"},                    new int[] {android.R.id.text1, android.R.id.text2}               );       view.setAdapter(listItemAdapter);    }        private ArrayList<HashMap<String, String>> readAllSMS() {    Cursor cursor = managedQuery(SMS_INBOX, new String[] { "address", "person", "body" },    null, null, null );    ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>> ();        if(cursor.moveToFirst()) {    int addrIdx = cursor.getColumnIndex("address");    int personIdx = cursor.getColumnIndex("person");    int bodyIdx = cursor.getColumnIndex("body");    do {    String addr = cursor.getString(addrIdx);    String person = cursor.getString(personIdx);    String body = cursor.getString(bodyIdx);        HashMap<String, String> item = new HashMap<String, String>();    item.put("addr", addr);    item.put("person", person);    item.put("body", body);    list.add(item);    } while(cursor.moveToNext());    }    return list;    }</span><span style="font-size:24px;"></span>
这里读取短信中收件箱的短信。如果全部短信内容时候,更改为:
Uri SMS_INBOX = Uri.parse("content://sms");

Activity::managedQuery函数基本上是一个接收SQL查询的接口,参数分别为: Parameters
uri The URI of the content provider to query.
projection List of columns to return.
selection SQL WHERE clause.
selectionArgs The arguments to selection, if any ?s are pesent
sortOrder SQL ORDER BY clause.

要读取短信,需要加入权限:
<uses-permission android:name="android.permission.READ_SMS"></uses-permission>

关于content://sms/inbox表,大致包含的域有:
_id | 短消息序号 如100
thread_id | 对话的序号 如100
address | 发件人地址,手机号.如+8613811810000
person | 发件人,返回一个数字就是联系人列表里的序号,陌生人为null
date | 日期 long型。如1256539465022
protocol | 协议 0 SMS_RPOTO, 1 MMS_PROTO
read | 是否阅读 0未读, 1已读
status | 状态 -1接收,0 complete, 64 pending, 128 failed
type | 类型 1是接收到的,2是已发出
body | 短消息内容
service_center | 短信服务中心号码编号。如+8613800755500

关于短信相关的应用,大致还包括:监听短信数据库(可用于监听短信的到来)、发送短信。使用起来基本上还算简单。

更多相关文章

  1. Android短信----接收流程---框架层(Frameworks)
  2. Android中短信的收发机制 发送短信 接收短信 拦截短信 监听短信
  3. android 中调用接口发送短信
  4. 【Android】Android6.0发送短信Demo
  5. android发送与接收超长短信
  6. 我的android 第二天 - 短信发送器
  7. Android NDK之发送短信
  8. Android 实现发送短信demo
  9. android > SMS 短信数据库访问

随机推荐

  1. android之数组排序
  2. Android(安卓)自定义CheckBox样式
  3. 导入color文件中的颜色值 android
  4. android webview pre[name=code] syntaxH
  5. android CursorAdapter
  6. 4.8.4 在Android 中fragment中获取上下文
  7. android studio 新建activity
  8. Android 开发入门-ListView 的用法
  9. android 图片圆角 遮罩_安卓圆角、背景遮
  10. 前端 Notes | H5 打开 App 并跳转指定页(An