I have seen many threads for accessing contacts from address book
, but apart from name
and number
, i want to access other details like- city, state, country, postal code
of the person. I have tried this code, but other things are null.
Cursor c = null;
try
{
Uri uri = data.getData();
c = getContentResolver().query(uri, new String[]
{
ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Phone.NUMBER,
ContactsContract.CommonDataKinds.StructuredPostal.CITY,
ContactsContract.CommonDataKinds.StructuredPostal.STREET,
ContactsContract.CommonDataKinds.StructuredPostal.COUNTRY },
null, null, null);
if (c != null && c.moveToFirst())
{
name = c.getString(0);
String number = c.getString(1);
city = c.getString(2);
street = c.getString(3);
country = c.getString(4);
Log.e("contactData...", name + ", " + street + ", " + number + ", " + city + ", " + country);
}
}
finally
{
if (c != null)
{
c.close();
}
}