Reputation: 25534
I am trying to access the contact details of a person which i selected from contact picker intent.
here is what my contact looks like:
Here is the code which i am using to open the contact picker:
Intent pickContactIntent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(pickContactIntent, PICK_CONTACT_REQUEST);
Now, i am able to get Phone number and email using following API's:
android.provider.ContactsContract.CommonDataKinds.Email;
android.provider.ContactsContract.CommonDataKinds.Phone;
but i am not able to get the address which is stored. I want to get both the address value and custom tag associated with it.
Any help is appreciated.
Upvotes: 3
Views: 3801
Reputation: 805
if You have a contact ID and you want to fetch the Postal Address then use this :
Uri postal_uri = ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_URI;
Cursor postal_cursor = getContentResolver().query(postal_uri,null, ContactsContract.Data.CONTACT_ID + "="+contactId.toString(), null,null);
while(postal_cursor.moveToNext())
{
String Strt = postal_cursor.getString(postal_cursor.getColumnIndex(StructuredPostal.STREET));
String Cty = postal_cursor.getString(postal_cursor.getColumnIndex(StructuredPostal.CITY));
String cntry = postal_cursor.getString(postal_cursor.getColumnIndex(StructuredPostal.COUNTRY));
}
postal_cursor.close();
http://gabrielaradu.com/?p=367
https://stackoverflow.com/a/13471370/2480911
Upvotes: 4