如何获取联系人的电子邮件ID? [英] How to get contact email id?

查看:159
本文介绍了如何获取联系人的电子邮件ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在手机中的所有联系人姓名的列表视图。我想这是我点击的列表视图联系人的电子邮件ID(如果接触有一个)。我怎样才能做到这一点?

I have a listview of all the contact names in the phone. I want to get the email id (if contact have one) of the contact which I click on in the listview. How can I do this?

推荐答案

使用下面的code来获取所有的电子邮件ID。我检查了code。这是工作。

Use the following code to get all email ids. I checked the code. It is working.

public static void getContactEmails(Context context) {
        String emailIdOfContact = null;
        int emailType = Email.TYPE_WORK;
        String contactName = null;


            ContentResolver cr = context.getContentResolver();
            Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null,
                    null, null, null);
            if (cur.getCount() > 0) {
                while (cur.moveToNext()) {
                    String id = cur.getString(cur
                            .getColumnIndex(BaseColumns._ID));
                    contactName = cur
                            .getString(cur
                                    .getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
                    // Log.i(TAG,"....contact name....." +
                    // contactName);

                    cr.query(
                            ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                            null,
                            ContactsContract.CommonDataKinds.Phone.CONTACT_ID
                                    + " = ?", new String[] { id }, null);

                    Cursor emails = cr.query(Email.CONTENT_URI, null,
                            Email.CONTACT_ID + " = " + id, null, null);
                    while (emails.moveToNext()) {
                        emailIdOfContact = emails.getString(emails
                                .getColumnIndex(Email.DATA));
                        // Log.i(TAG,"...COntact Name ...."
                        // + contactName + "...contact Number..."
                        // + emailIdOfContact);
                        emailType = emails.getInt(emails
                                .getColumnIndex(Phone.TYPE));


                    }
                    emails.close();

                }
            }// end of contact name cursor
            cur.close();


    }

这篇关于如何获取联系人的电子邮件ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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