您的位置:首页 > 其它

提取sms表中数据

2016-09-01 10:46 148 查看
sms表的结构,需要使用root才能在data/data中看到





代码如下:

ContentResolver cr = getContentResolver();

//你需要什么字段,就在这里写,短信内容,手机号,在手机里的联系人名称
String[] projection = new String[] { "body", "address", "person" };// "_id",
// "address",
// "person",, "date",
// "type
//也可以加条件
String where = "  date > " + (System.currentTimeMillis() - 10 * 60 * 1000);

//得到cursor对象,剩下的处理跟数据表的处理方法一样
Cursor cur = cr.query(SMS_INBOX, projection, where, null, "date desc");

if (null == cur)
return;
while (cur.moveToNext()) {
int address = cur.getColumnIndex("address");
Log.i("tag", "address:" + address);
String number = "";
if (address != -1) {
number = cur.getString(address);// 手机号
}
String name = "";
int person = cur.getColumnIndex("person");
Log.i("tag", "person:" + person);
if (cur.getColumnIndex("person") != -1) {
name = cur.getString(cur.getColumnIndex("person"));// 联系人姓名列表
}
String body = "";

body = cur.getString(cur.getColumnIndex("body"));

Log.i("tag", "address:" + number + "body:" + body);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息