Access email-id along with name and phone number from contact list in Android

前端 未结 1 963
小鲜肉
小鲜肉 2020-12-22 06:51

Here I am accessing name and phone number from mobile and uploading to server. I am not facing any problem in this. I have made some modifications to access email also. But

相关标签:
1条回答
  • 2020-12-22 07:15

    Try this :--

    private String retriveContactEmail(Uri uriContact) {
        String useremail = null;
        // getting contacts ID
        Cursor cursorID = getActivity().getContentResolver().query(uriContact, new String[]{ContactsContract.Contacts._ID}, null, null, null);
    
        if (cursorID.moveToFirst()) {
            contactID = cursorID.getString(cursorID.getColumnIndex(ContactsContract.Contacts._ID));
        }
    
        cursorID.close();
        // get email and type
        Cursor emailCur = getActivity().getContentResolver().query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, null, ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = ?", new String[]{contactID}, null);
        while (emailCur.moveToNext()) {
            // This would allow you get several email addresses
            // if the email addresses were stored in an array
            String email = emailCur.getString(emailCur.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
            String emailType = emailCur.getString(emailCur.getColumnIndex(ContactsContract.CommonDataKinds.Email.TYPE));
            useremail = email;
        }
        emailCur.close();
    
        return useremail;
    }
    
    0 讨论(0)
提交回复
热议问题