gpt4 book ai didi

Android People.Number 和 People.Number_key 返回 null

转载 作者:太空宇宙 更新时间:2023-11-03 11:23:30 27 4
gpt4 key购买 nike

我正在尝试从电话中获取联系人,但我只能获取姓名,电话号码返回空值。

       Cursor cursor = getContentResolver().query(People.CONTENT_URI, null, null, null,People.NAME + " ASC");
startManagingCursor(cursor);
cursor.moveToFirst();
if(cursor.getCount() > 0){
while(cursor.moveToNext()){
int idCol = cursor.getColumnIndex(People._ID);
int nameCol = cursor.getColumnIndex(People.NAME);
int numCol = cursor.getColumnIndex(People.NUMBER_KEY);

String name = cursor.getString(nameCol);
String number = cursor.getString(numCol);
//mDbHelper.addContact(managedCursor.getString(1),managedCursor.getString(2));
Log.v("contact.add",name+" - "+number);
}

有什么想法吗?

大约3个小时后,我想通了:

   ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,
null, null, null, null);
if (cur.getCount() > 0) {
cur.move(-1);
while (cur.moveToNext()) {
String id = cur.getString(
cur.getColumnIndex(ContactsContract.Contacts._ID));
String name = cur.getString(
cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
if (Integer.parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
if (Integer.parseInt(cur.getString(
cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
Cursor pCur = cr.query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?",
new String[]{id}, null);
while (pCur.moveToNext()) {

Log.v("Phone",""+pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER))+" - "+name);
i++;
}
pCur.close();
}

}
}
}

最佳答案

电话号码列是 People.NUMBER,而不是 People.NUMBER_KEY。

关于Android People.Number 和 People.Number_key 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3126219/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com