加载所有联系人和所有电话号码的有效方法(Android 2.0)
有没有一种方法可以获取所有联系人的所有电话号码,而无需对每个联系人进行单独的查询? (使用Android 2.0+)。如果您有超过 100 个联系人(在低端手机上无法使用),它真的很慢,我想知道是否可以进行更有效的查询。
目前,我正在获取包含所有有效 ContactsContract.Contacts.IN_VISIBLE_GROUP 联系人的游标,然后对每个联系人进行单独的查询以获取其所有号码。
来自获取联系人的片段仅获取姓名和查找键:
Uri uri = ContactsContract.Contacts.CONTENT_URI;
String[] projection = new String[] {
ContactsContract.Contacts.DISPLAY_NAME,
ContactsContract.Contacts.LOOKUP_KEY};
然后每个联系人都使用查找键。
Uri lookupUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookupKey);
Uri res = ContactsContract.Contacts.lookupContact(contentResolver, lookupUri);
String[] projection = new String[]{ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME, ContactsContract.Contacts.HAS_PHONE_NUMBER};
...
Cursor phones = contentResolver.query( ContactsContract.CommonDataKinds.Phone.CONTENT_URI, phoneProjection, selection, selectionArgs, sortOrder);
Is there a way of getting all the phone numbers for all contacts without doing a separate query for each contact? (using Android 2.0+). It's really slow if you have over 100 contacts (unusable on low end phones), I wondered if I could do a more efficient query.
Currently I'm getting a cursor with all valid ContactsContract.Contacts.IN_VISIBLE_GROUP contacts then a separate query for each contact to get all their numbers.
Snippet from the get Contacts just geting name and lookup key:
Uri uri = ContactsContract.Contacts.CONTENT_URI;
String[] projection = new String[] {
ContactsContract.Contacts.DISPLAY_NAME,
ContactsContract.Contacts.LOOKUP_KEY};
Then each contact using the lookup key.
Uri lookupUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookupKey);
Uri res = ContactsContract.Contacts.lookupContact(contentResolver, lookupUri);
String[] projection = new String[]{ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME, ContactsContract.Contacts.HAS_PHONE_NUMBER};
...
Cursor phones = contentResolver.query( ContactsContract.CommonDataKinds.Phone.CONTENT_URI, phoneProjection, selection, selectionArgs, sortOrder);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
检查以下代码是否有帮助
Check if the below code helps