我的Android應用程序需要檢索有關聯繫人的信息(即電話號碼和姓名)。我使用getContentResolver().query()
編寫了一些代碼在結果中,我看到名稱是被退回,以及其他信息,例如,我上次聯繫該人時,但不是電話號碼。我究竟做錯了什麼?在我的Android應用程序中無法獲取電話號碼
代碼:
Log.w("MyApp", "requesting " + phonesUri.toString());
Cursor contactCursor = context.getContentResolver().query(person, null, null, null, null);
contactCursor.moveToFirst();
for (int i = 0; i < contactCursor.getColumnCount(); i ++) {
Log.w("MyApp", contactCursor.getColumnName(i) + ": " + contactCursor.getString(i));
}
它輸出這樣的:
W/MyApp (21477): requesting content://contacts/people/169/phones
W/MyApp (21477): times_contacted: 6
W/MyApp (21477): custom_ringtone: null
W/MyApp (21477): primary_organization: null
W/MyApp (21477): phonetic_name:
W/MyApp (21477): status: null
W/MyApp (21477): label: null
W/MyApp (21477): number: null
W/MyApp (21477): type: null
W/MyApp (21477): mode: null
W/MyApp (21477): last_time_contacted: 1278113641980
W/MyApp (21477): display_name: (name removed for privacy)
W/MyApp (21477): im_handle: null
W/MyApp (21477): _id: 169
W/MyApp (21477): number_key: null
W/MyApp (21477): starred: 0
W/MyApp (21477): primary_email: null
W/MyApp (21477): name: (name removed for privacy)
W/MyApp (21477): primary_phone: null
W/MyApp (21477): im_account: null
W/MyApp (21477): notes:
W/MyApp (21477): im_protocol: null
W/MyApp (21477): send_to_voicemail: 0
謝謝。看起來舊的Eclair之前的東西不再可靠地工作了。一旦我切換到ContactsContract,事情就開始奏效。 – 2010-07-07 21:23:17