我正在尝试从手机的短信收件箱中查找与短信相对应的联系方式。据我了解,该person列_id是ContactsContract.Contacts.
我的问题是我person从短信查询中得到了错误的值。person联系人表中不存在某些id,而有些则指向完全不同的联系人。
下面是我用于获取person值列表的代码,谁能告诉我我是否遗漏了什么或遇到了类似的问题。
使用运行 Android 4.1.2 的 Nexus S 进行测试
Uri parsedUri = Uri.parse("content://sms/inbox");
String[] projection = new String[] { "_id", "address", "person" };
Cursor cursor = contentResolver.query(parsedUri, projection, null, null, null);
Log.d(TAG, "Total Count " + cursor.getCount());
if (cursor.getCount() > 0) {
// String address;
int person;
int personIndex = cursor.getColumnIndex("person");
if (cursor.moveToFirst())
do {
person = cursor.getInt(personIndex);
if (person > 0) {
// Add this id to a list
}
} while (cursor.moveToNext());
}
cursor.close();
更新:我正在查看Android Developer Portal(http://developer.android.com/guide/topics/providers/contacts-provider.html)的一些文档,是否有可能person从短信收件箱中检索到的 id 指的是而ContactsContract.RawContacts不是ContactsContract.Contacts我所做的。