【发布时间】:2014-04-17 19:05:52
【问题描述】:
我正在使用以下光标来检索仅在手机中的联系人?但是,该代码为我提供了 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();
}
}
【问题讨论】:
标签: java android android-contacts android-cursoradapter