Android:sms PERSON属性与联系人的_ID不同

时间:2016-02-26 17:44:24

标签: android database attributes contact

我遇到了android数据库的一些问题。

我已使用以下代码从默认的android数据库中填充contactObject类:

/**
 * this function fill a contact with a given phoneNumber
 * @param phoneNumber the phone number to fill the contact
 * @return the recently created contact
 */
public Contact fillContact(String phoneNumber) {
    Contact contact = new Contact(phoneNumber);
    contact.setName(phoneNumber);
    ContentResolver cr = getCurrentContex().getContentResolver();
    Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber));
    Cursor cur = cr.query(uri, null, null, null, null);
    if (cur.getCount() > 0) {
        while (cur.moveToNext()) {
            String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
            String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
            contact.setId(Integer.valueOf(id));
            contact.setName(name);
        }
    }
    cur.close();
    return contact;
}

但是,当我想从Telephony.Sms表格恢复短信时,PERSON属性与contact.getId()不同。

如何在联系人中获得PERSON属性的等价物?

非常感谢。

0 个答案:

没有答案