要使用CommonDataKinds.Phone内部查询使ContactsContract.Contact查询更快,可以采取以下步骤:
Cursor cursor = getContentResolver().query(
ContactsContract.Contacts.CONTENT_URI,
null,
null,
null,
null
);
String[] projection = {
ContactsContract.Contacts._ID,
ContactsContract.Contacts.DISPLAY_NAME,
ContactsContract.Contacts.HAS_PHONE_NUMBER
};
Cursor cursor = getContentResolver().query(
ContactsContract.Contacts.CONTENT_URI,
projection,
null,
null,
null
);
String selection = ContactsContract.Contacts.HAS_PHONE_NUMBER + " = 1";
Cursor cursor = getContentResolver().query(
ContactsContract.Contacts.CONTENT_URI,
projection,
selection,
null,
null
);
Cursor phoneCursor = getContentResolver().query(
CommonDataKinds.Phone.CONTENT_URI,
null,
CommonDataKinds.Phone.CONTACT_ID + " = ?",
new String[]{contactId},
null
);
String[] phoneProjection = {
CommonDataKinds.Phone.NUMBER
};
Cursor phoneCursor = getContentResolver().query(
CommonDataKinds.Phone.CONTENT_URI,
phoneProjection,
CommonDataKinds.Phone.CONTACT_ID + " = ?",
new String[]{contactId},
null
);
推荐的腾讯云相关产品:腾讯云移动推送(https://cloud.tencent.com/product/umeng_push)、腾讯云短信验证码(https://cloud.tencent.com/product/sms_code)。
请注意,以上答案仅供参考,具体实现方式可能因应用需求和环境而异。
领取专属 10元无门槛券
手把手带您无忧上云