0
我正在使用以下光標來檢索手機中的通訊錄?但是,該代碼給我在SIM和手機中的聯繫人。是否有可能僅通過電話獲取聯繫人,他們的照片(如果可用),電話號碼和顯示名稱?安卓手機通訊錄僅適用於照片,手機和名稱
cursor = getContentResolver().query(Phone.CONTENT_URI, null, null, null, null);
int contactIdIdx = cursor.getColumnIndex(Phone._ID);
int nameIdx = cursor.getColumnIndex(Phone.DISPLAY_NAME);
int phoneNumberIdx = cursor.getColumnIndex(Phone.NUMBER);
int photoIdIdx = cursor.getColumnIndex(Phone.PHOTO_ID);
cursor.moveToFirst();
do {
try {
Contact c = new Contact();
String idContact = cursor.getString(contactIdIdx);
String name = cursor.getString(nameIdx);
c.setName(name);
Log.i(TAG,storage.getDriveName()+": "+name);
String phoneNumber = cursor.getString(phoneNumberIdx);
Log.i(TAG,storage.getDriveName()+": "+phoneNumber);
c.setPhoneNumber(phoneNumber);
if(phoneNumber != null)
c.setPhotoUri(getPhotoUri(Long.valueOf(fetchContactIdFromPhoneNumber(phoneNumber))));
contacts.add(cbd);
} catch(Exception e) {
Log.e(TAG,storage.getDriveName()+": "+e.getMessage());
}
} while (cursor.moveToNext());
} catch (Exception e) {
Log.e(TAG,storage.getDriveName()+": "+e.getMessage());
}
if (cursor != null) {
cursor.close();
}
}