在我看来,在 Android 上访问联系人是如此缓慢,而且不必要地涉及游标。如何加速?
最佳答案
1.当您第一次阅读联系人时,您可能会减少一些属性(property)。
2.读取一类属性时,可以使用游标。
private static final String[] CONTACTOR_ION = new String[]{
ContactsContract.CommonDataKinds.Phone.CONTACT_ID,
ContactsContract.Contacts.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Phone.NUMBER
};
Cursor phones = null;
ContentResolver cr = getContentResolver();
try {
phones = cr
.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI
, CONTACTOR_ION, null, null, "sort_key");
if (phones != null) {
final int contactIdIndex = phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.CONTACT_ID);
final int displayNameIndex = phones.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
final int phoneIndex = phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
String phoneString, displayNameString, contactIdString;
while (phones.moveToNext()) {
phoneString = phones.getString(phoneIndex);
displayNameString = phones.getString(displayNameIndex);
contactIdString = phones.getString(contactIdIndex);
}
}
} catch (Exception e) {
Log.e(TAG, e.getMessage());
} finally {
if (phones != null)
phones.close();
}
关于android - 如何加快访问 Android 上的联系人?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36347290/