質問

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:

enter image description here

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.

役に立ちましたか?

解決

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top