【发布时间】:2013-01-13 20:23:59
【问题描述】:
我正在尝试从手机的短信收件箱中查找与短信对应的联系方式。据我了解,person 列是ContactsContract.Contacts 的_id 列的外键。
我的问题是我从短信查询中得到了错误的 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正如我所做的那样。
【问题讨论】:
-
您首先检查联系人列表中是否存在人员号码。如果是,则匹配两个id。
标签: android message android-contacts