androidの读取短信内容
- androidの读取短信内容 推荐度:
- 相关推荐
androidの读取短信内容
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
关于短信相关的应用,大致还包括:监听短信数据库(可用于监听短信的到来)、发送短信。使用起来基本上还算简单。
最新文章
- matlab stats里的f值,MATLAB 回归分析regress,nlinfit,stepwise函数
- 获取rowid的两种方法。
- Android权限
- php操作 JSON格式数据
- MSYS 1.0.11 + MinGW安装方法
- MinGW+MSYS安装
- 文本长度过长时隐藏并显示省略号“...”,以及鼠标停留时悬浮显示全部文本(兼容IE)
- gallery3D(3)
- VSS2005使用技巧
- EXT2和3区别
- MongoDB勒索事件中,DBA们到底该学到什么?
- Android4.4深入浅出之SurfaceFlinger与Client通信框架(一)
- TCP Socket与TCP 连接
- hashtable的解释
- SimpleDateFormat的坑
- SVM算法实现(一)
- pgpool连接池
- 装机、做系统必备:秒懂MBR和GPT分区表
- 在android项目上集成libyuv库以及使用libyuv库完成camera的缩放,旋转,翻转,裁剪操作
- global mapper裁剪DEM文件的方法