I have an app which can retrieve the mailing address from contact
information on the device. I retrieve the information for street address,
post code, city etc. using the contacts API using code similar to below. I
then display the address on separate lines and the user can accept it or
change it if desired.
String where = ContactsContract.Data.CONTACT_ID + " = ? AND " +
ContactsContract.Data.MIMETYPE + " = ?";
String[] params = new String[]{id,
ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE};
Cursor addrCur =
getContentResolver().query(ContactsContract.Data.CONTENT_URI, null, where,
params, null);
...
while(addrCur.moveToNext()) {
String street =
addrCur.getString(addrCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.STREET));
String city =
addrCur.getString(addrCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.CITY));
String state =
addrCur.getString(addrCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.REGION));
String postalCode =
addrCur.getString(addrCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.POSTCODE));
String country =
addrCur.getString(addrCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.COUNTRY));
...
}
addrCur.close();
This has worked fine with Android 2.2/2.3 but I noticed on 3.x and higher
that the entire address that is returned can be formatted as a single
string with line breaks in the STREET field. This occurs when the
contact/address is created on the device; if I sync a contact from Gmail,
the address is retrieved correctly (I suspect that the synced info is saved
in the correct fields). I can't see any way to get the individual data
elements (street, postcode, etc) for these types of addresses. Is this
possible? Is there a new API I need to use?
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en