如何从Android 1.6中的联系人获取电子邮件ID?

时间:2011-02-21 15:41:25

标签: android contacts

您好 我正在开发一个基于联系人的应用程序,因为我希望从联系人到我的应用程序获取电子邮件ID

我正在开发android 1.6的应用程序

请帮助我做任何事。谢谢提前

2 个答案:

答案 0 :(得分:0)

您可以参考此链接http://thinkandroid.wordpress.com/2010/01/19/retrieving-contact-information-name-number-and-profile-picture/

找到第String[] columns = new String[] { People.NAME, People.NUMBER };行 你可以使用这个http://developer.android.com/reference/android/provider/Contacts.People.html#PRIMARY_EMAIL_ID

获取电子邮件ID。我不确定这个,但是你可以尝试一下

答案 1 :(得分:-3)

ContentResolver cr = getContentResolver();
            Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null,
                    null, null, null);
            int index = 0;

            if (cur.getCount() > 0) {

                emailNames = new String[cur.getCount()];
                emailNumbers = new String[cur.getCount()];

                while (cur.moveToNext()) {
                    String id = cur.getString(cur
                            .getColumnIndex(ContactsContract.Contacts._ID));
                    name = cur
                            .getString(cur
                                    .getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
                    emailNames[index] = name;

                    Cursor emails = getContentResolver().query(
                            ContactsContract.CommonDataKinds.Email.CONTENT_URI,
                            null,
                            ContactsContract.CommonDataKinds.Email.CONTACT_ID
                                    + " = " + id, null, null);
                    while (emails.moveToNext()) {
                        // This would allow you get several email addresses
                        String emailAddress = emails
                                .getString(emails
                                        .getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
                        Log.v("email==>", emailAddress);


                            emailNumbers[index] = emailAddress;

                        }
                    }
                    emails.close();
                    index++;

                }
                cur.close();