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

前端 未结 2 539
余生分开走
余生分开走 2021-01-16 20:16

Hi I am developing 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

相关标签:
2条回答
  • 2021-01-16 20:52
    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 讨论(0)
  • 2021-01-16 20:56

    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

    0 讨论(0)
提交回复
热议问题