我看到很多線程來訪問聯繫人從address book
,但除了name
和number
,我想訪問其他詳細信息,如 - city, state, country, postal code
的人。我試過這段代碼,但其他的東西都是空的。尋找從地址簿中選擇的城市,國家,郵政編碼
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();
}
}
請參閱這裏: - http://stackoverflow.com/questions/18181204/when-i-select-contact-name-and-address-from-contact-list-address-data-not-retrie – Sachchidanand