在我的光標查詢該選擇條款只返回那些誰有一個電話號碼,這正是我想要的聯繫人:如何獲取我的通訊錄中相應姓名的電話號碼?
// we only want contacts that have a name and a phone number. If they have a phone number, the value is 1 (if not, it is 0)
ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '" + ("1") + "'" + " AND " + ContactsContract.Contacts.HAS_PHONE_NUMBER + "=1",
我的整個遊標查詢看起來是這樣的:
// this query only return contacts with phone number and is not duplicated
phones = getContentResolver().query(
// the table to query
ContactsContract.Contacts.CONTENT_URI,
// the columns to return
null,
// selection criteria :
// we only want contacts that have a name and a phone number. If they have a phone number, the value is 1 (if not, it is 0)
ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '" + ("1") + "'" + " AND " + ContactsContract.Contacts.HAS_PHONE_NUMBER + "=1",
// selection criteria
null,
// display in ascending order
ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC");
卻怎麼也我爲每個聯繫人獲得實際的電話號碼?我可以在上面的代碼中添加一些東西,還是需要啓動一個新的Cursor查詢?
我認爲這是後者。
我開始了新的遊標查詢爲出發點:
phonestwo = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.Phone.IN_VISIBLE_GROUP + " = '" + ("1") + "'" + " AND " + ContactsContract.CommonDataKinds.Phone.HAS_PHONE_NUMBER + "=1",
null,
null);
但在日誌中的logcat我收到手機光標有134個記錄(正確的,我想要的!),我的phonestwo光標196記錄。總之,如何獲得與這134條記錄相對應的電話號碼?