Android 手机信息存放在mmssms.db数据库。
短讯息主要用到sms表和threads表。
查看其表结构
sms表,信息表
threads表
1.mesage_count该会话的消息数量
2.recipient_ids为联系人ID,这个ID不是联系人表中的_id,而是指向表canonical_address里的id,
canonical_address这个表同样位于mmssms.db,它映射了recipient_ids到一个电话号码,也就是说,
最终获取联系人信息,还是得通过电话号码;
3.snippet为最后收到/发出的信息
4._id为会话id,他关联到sms表中的thread_id字段。
Cursor cursor = cr.query(Uri.parse("content://sms/"), new String[] { "* from threads--" }, null, null, null);
查询Threads表。
网上说Threads的URI为:"content://mms-sms/conversations"
不过由于本人使用这个Uri查询出错,故使用content://sms/ 通过构造查询字段数组来查询Threads表。
public static List<Threads> getSession(ContentResolver cr) { Cursor cursor = cr.query(Uri.parse("content://sms/"), new String[] { "* from threads--" }, null, null, null); list = new ArrayList<Threads>(); if (cursor.moveToFirst()) { do { if (threads == null) { threads = new Threads(); } threads.set_id(cursor.getInt(ID)); threads.setDate(cursor.getLong(DATE)); threads.setError(cursor.getInt(ERROR)); threads.setHas_attachment(cursor.getInt(HAS_ATTACHMENT)); threads.setMessage_count(cursor.getInt(MESSAGE_COUNT)); threads.setRead(cursor.getInt(READ)); threads.setRecipient_ids(cursor.getString(RECIPIENT_IDS)); threads.setSnippet(cursor.getString(SNIPPET)); threads.setSnippet_cs(cursor.getInt(SNIPPET_CS)); threads.setType(cursor.getInt(TYPE)); list.add(threads); threads = null; } while (cursor.moveToNext()); } return list; }
最后通过获取到的thread_id作为参数再去查询sms表。就可以获取每个会话的所有信息。