我遇到了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属性的等价物?
非常感谢。