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

前端 未结 2 538
余生分开走
余生分开走 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();
    

提交回复
热议问题