Android 仅对列出了电子邮件的联系人获取光标

发布于 2024-10-26 04:25:30 字数 1837 浏览 0 评论 0原文

朋友,我想要有电子邮件并按升序排序的联系人。

任何人都知道如何获取此列表并排序。

请帮助我并提前致谢。

我正在使用这段代码。

        MatrixCursor matCur = new MatrixCursor(new String[] { Contacts._ID,
                Contacts.DISPLAY_NAME, "photo_id", "starred" });
        Cursor cEmail = WP7Main.this.managedQuery(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
        cEmail.moveToFirst();
        if (cEmail.moveToFirst()) 
        {
            // String name =
            // cursor.getString(cursor.getColumnIndexOrThrow(People.NAME));

            String contactId = cEmail.getString(cEmail.getColumnIndex(ContactsContract.Contacts._ID));

            Cursor emails = WP7Main.this.getContentResolver().query(ContactsContract.CommonDataKinds.Email.CONTENT_URI,
            null,ContactsContract.CommonDataKinds.Email.CONTACT_ID+ " = " + contactId, null, null);

            String emailAddress = "";
            while (emails.moveToNext()) 
            {
                // This would allow you get several email addresses

                if (emails.getString(emails.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA)) != null)
                {
                    String[] columnValues = {
                            cEmail.getString(cEmail
                                    .getColumnIndex("_id")),
                                    cEmail.getString(cEmail
                                    .getColumnIndex("display_name")),
                                    cEmail.getString(cEmail
                                    .getColumnIndex("photo_id")),
                                    cEmail.getString(cEmail
                                    .getColumnIndex("starred")) };
                    matCur.addRow(columnValues);

                }

            }
            emails.close();
        }

Friends I want Contacts which have email and also sort in ascending order..

any one know how to get this list and sort..

Please help me and thanks in advance.

I am using this code.

        MatrixCursor matCur = new MatrixCursor(new String[] { Contacts._ID,
                Contacts.DISPLAY_NAME, "photo_id", "starred" });
        Cursor cEmail = WP7Main.this.managedQuery(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
        cEmail.moveToFirst();
        if (cEmail.moveToFirst()) 
        {
            // String name =
            // cursor.getString(cursor.getColumnIndexOrThrow(People.NAME));

            String contactId = cEmail.getString(cEmail.getColumnIndex(ContactsContract.Contacts._ID));

            Cursor emails = WP7Main.this.getContentResolver().query(ContactsContract.CommonDataKinds.Email.CONTENT_URI,
            null,ContactsContract.CommonDataKinds.Email.CONTACT_ID+ " = " + contactId, null, null);

            String emailAddress = "";
            while (emails.moveToNext()) 
            {
                // This would allow you get several email addresses

                if (emails.getString(emails.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA)) != null)
                {
                    String[] columnValues = {
                            cEmail.getString(cEmail
                                    .getColumnIndex("_id")),
                                    cEmail.getString(cEmail
                                    .getColumnIndex("display_name")),
                                    cEmail.getString(cEmail
                                    .getColumnIndex("photo_id")),
                                    cEmail.getString(cEmail
                                    .getColumnIndex("starred")) };
                    matCur.addRow(columnValues);

                }

            }
            emails.close();
        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

久而酒知 2024-11-02 04:25:30

试试这个:

/**
 * @return A managed cursor of email contacts for the given activity.
 */
public static Cursor buildFilteredEmailCursor(Activity activity) {
    final String my_sort_order = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC";
    String my_selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '1'";
    String[] eproj = new String[]{
        ContactsContract.Contacts._ID,
        ContactsContract.Contacts.DISPLAY_NAME,
        ContactsContract.CommonDataKinds.Email.DATA};
    Uri uri = android.provider.ContactsContract.CommonDataKinds.Email.CONTENT_URI;
    return activity.managedQuery(uri, eproj, my_selection, null, my_sort_order);
}

Try this:

/**
 * @return A managed cursor of email contacts for the given activity.
 */
public static Cursor buildFilteredEmailCursor(Activity activity) {
    final String my_sort_order = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC";
    String my_selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '1'";
    String[] eproj = new String[]{
        ContactsContract.Contacts._ID,
        ContactsContract.Contacts.DISPLAY_NAME,
        ContactsContract.CommonDataKinds.Email.DATA};
    Uri uri = android.provider.ContactsContract.CommonDataKinds.Email.CONTENT_URI;
    return activity.managedQuery(uri, eproj, my_selection, null, my_sort_order);
}
我是男神闪亮亮 2024-11-02 04:25:30

使用此查询:

Cursor c = getContentResolver().query(Data.CONTENT_URI,
        new String[]{Data.CONTACT_ID, Data.DISPLAY_NAME, Email.ADDRESS},
        Data.MIMETYPE + "=?", new String[] {Email.CONTENT_TYPE}, Data.DISPLAY_NAME /* use Email.ADDRESS if you want to sort it using that*/);

Use this query :

Cursor c = getContentResolver().query(Data.CONTENT_URI,
        new String[]{Data.CONTACT_ID, Data.DISPLAY_NAME, Email.ADDRESS},
        Data.MIMETYPE + "=?", new String[] {Email.CONTENT_TYPE}, Data.DISPLAY_NAME /* use Email.ADDRESS if you want to sort it using that*/);

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文