Last active
August 29, 2015 14:10
-
-
Save hitenpratap/3c6238cf2b7351e8981c to your computer and use it in GitHub Desktop.
fetch all Email Addresses associated with particular Contact Id
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private Map<String,String> fetchEmails(String id,ContentResolver cr){ | |
Cursor emailDataCursor = cr.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, null, | |
ContactsContract.CommonDataKinds.Email.CONTACT_ID + "=?", new String[]{id}, null); | |
if (emailDataCursor.getCount() > 0) { | |
Map<String,Map<String,String>> emailMap = new HashMap<String, Map<String, String>>(); | |
while (emailDataCursor.moveToNext()) { | |
Map<String,String> tempEmailMap = new HashMap<String,String>(); | |
String emailData = emailDataCursor.getString(emailDataCursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA)); | |
String emailType = emailDataCursor.getString(emailDataCursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.TYPE)); | |
String customLabel = emailDataCursor.getString(emailDataCursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.LABEL)); | |
CharSequence emailTypeLabel = ContactsContract.CommonDataKinds.Email.getTypeLabel(context.getResources(), emailDataCursor.getInt(emailDataCursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.TYPE)), customLabel); | |
tempEmailMap.put((String) emailTypeLabel,emailData); //will contain label and email address | |
emailMap.put(emailType,tempEmailMap); //will contail email Id and map of label and number | |
} | |
} | |
return emailMap; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment