开发者

How to get the email id from contacts in android 1.6?

开发者 https://www.devze.com 2023-02-12 15:24 出处:网络
Hi I am devel开发者_如何学编程oping a contact based application in that i want get the email id from the contacts to my application

Hi I am devel开发者_如何学编程oping a contact based application in that i want get the email id from the contacts to my application

I am developing the application for android 1.6

Please any on help me to do that.Thanks in advance


You can refer to this link http://thinkandroid.wordpress.com/2010/01/19/retrieving-contact-information-name-number-and-profile-picture/

find the line String[] columns = new String[] { People.NAME, People.NUMBER }; and you can use this http://developer.android.com/reference/android/provider/Contacts.People.html#PRIMARY_EMAIL_ID

to get email id. I am not sure on this but yes you can give it a try


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号