Android 仅在列出了电子邮件的联系人中获取光标 >android 2.0
我有以下代码来从内容提供商
获取联系人
String[] columns = new String[] {
ContactsContract.Contacts.DISPLAY_NAME,
ContactsContract.Contacts._ID,
ContactsContract.Contacts.PHOTO_ID };
Cursor cursor = managedQuery(ContactsContract.Contacts.CONTENT_URI,
columns, null, null, null);
,并使用此代码通过 ID 获取特定联系人的电子邮件:
Cursor emails = getContentResolver().query(
ContactsContract.CommonDataKinds.Email.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.Email.CONTACT_ID
+ " = " + contact.getContactId(), null, null);
我当前的实现传递光标中的每一行并获取其电子邮件并存储它们位于 java 对象的 arrayList 中。
我想知道是否可以做的只是查询内容提供商并返回包含 ids/name 等联系人的光标,其中列出了电子邮件地址。
这种方式获取联系人列表的等待时间较长。我正在使用此列表作为列表适配器。如果我只能获取有电子邮件的联系人,我可以在列表中使用光标适配器。
这样的事情可能吗?我怎样才能加快这个过程?
i have the following code to get contacts from content provider
String[] columns = new String[] {
ContactsContract.Contacts.DISPLAY_NAME,
ContactsContract.Contacts._ID,
ContactsContract.Contacts.PHOTO_ID };
Cursor cursor = managedQuery(ContactsContract.Contacts.CONTENT_URI,
columns, null, null, null);
and i use this one to get the emails for a specific contact by their id:
Cursor emails = getContentResolver().query(
ContactsContract.CommonDataKinds.Email.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.Email.CONTACT_ID
+ " = " + contact.getContactId(), null, null);
my current implementation passes every row in the cursor and aquires its emails and stores them in an arrayList of java objects.
what i was wondering if it was possible to do is just query the content provider and return a cursor of just contacts with ids/name etc that have an email address listed.
this way has a long waiting period for getting the contact list. i am using this list for a list adapter. if i can get only the contacts that have an email i can use a cursor adapter in my list.
Is something like this possible? how can i speed up the process?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
@CapDroid
修复了 DArkO 帖子中的工作代码:
您的光标将包含基本 ID 以及姓名和电子邮件地址。该代码的性能非常好,因为它只请求很少的列。
@CapDroid
Fixed working code from DArkO's post:
Your cursor will have essential IDs as well as names and email addresses. The performance of this code is great because it requests few columns only.
我解决了这个问题,这是如何完成的:
更新
I solved this one, here is how its done:
UPDATE