Android开光标只能与有一封电子邮件中列出&GT联系;安卓2.0 [英] Android get a cursor only with contacts that have an email listed >android 2.0

查看:113
本文介绍了Android开光标只能与有一封电子邮件中列出&GT联系;安卓2.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下code,以获得内容提供商的接触

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);

和我用这个来获取电子邮件通过它们的ID特定联系人:

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);

我目前的执行情况通过每一行中的光标,aquires的电子邮件,并将其存储在Java对象的ArrayList

my current implementation passes every row in the cursor and aquires its emails and stores them in an arrayList of java objects.

我想知道是否有可能做的仅仅是查询的内容提供商,并返回游标的使用IDS /名称等,具有列出的电子邮件地址刚刚接触。

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?

推荐答案

我解决了这一个,这里是如何做:

I solved this one, here is how its done:

更新

   String[] PROJECTION = new String[] { ContactsContract.RawContacts._ID,
        ContactsContract.Contacts.DISPLAY_NAME, ContactsContract.Contacts.PHOTO_ID,
        Email.DATA, ContactsContract.CommonDataKinds.Photo.CONTACT_ID };

    String order = " CASE WHEN " + ContactsContract.Contacts.DISPLAY_NAME
        + " NOT LIKE '%@%' THEN 1" + " ELSE 2 END, "
        + ContactsContract.Contacts.DISPLAY_NAME + " COLLATE NOCASE";
    String filter = Email.DATA + " NOT LIKE '' ) GROUP BY ( " + Email.DATA;

    return mContent.query(Email.CONTENT_URI,
                      PROJECTION, filter, null, order);

这篇关于Android开光标只能与有一封电子邮件中列出&GT联系;安卓2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆