提取sms表中数据





sms表的结构,需要使用root才能在data/data中看到

提取sms表中数据_第1张图片

代码如下:

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);


}


你可能感兴趣的:(提取sms表中数据)