Created
December 2, 2014 19:00
-
-
Save hitenpratap/5d3872f922ea792990a3 to your computer and use it in GitHub Desktop.
fetch all Phone numbers 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> fetchPhones(String id,ContentResolver cr){ | |
Cursor phoneDataCursor = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, | |
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + "=?", new String[]{id}, null); | |
if (phoneDataCursor.getCount() > 0) { | |
Map<String,Map<String,String>> phoneMap = new HashMap<String, Map<String, String>>(); | |
while (phoneDataCursor.moveToNext()) { | |
Map<String,String> tempPhoneMap = new HashMap<String,String>(); | |
String phoneData = phoneDataCursor.getString(phoneDataCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DATA)); | |
String phoneType = phoneDataCursor.getString(phoneDataCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE)); | |
String customLabel = phoneDataCursor.getString(phoneDataCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.LABEL)); | |
CharSequence phoneTypeLabel = ContactsContract.CommonDataKinds.Phone.getTypeLabel(context.getResources(), phoneDataCursor.getInt(phoneDataCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE)), customLabel); | |
tempPhoneMap.put((String) phoneTypeLabel,phoneData); //will contain label and number | |
phoneMap.put(phoneType,tempPhoneMap); //will contail phone Id and map of label and number | |
} | |
} | |
return phoneMap; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment