从联系人那里获取地址但仍然获得号码?

时间:2015-09-26 16:17:20

标签: android eclipse

我使用以下代码从联系中获取号码,但我仍然获得联系人的手机号码。

Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,null,null, null);
    while (phones.moveToNext())
    {

      String address=phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.FORMATTED_ADDRESS));

      Toast.makeText(getBaseContext(), "Address is:"+address, Toast.LENGTH_SHORT).show();   
    }

在祝酒词中,我收到了联系人的手机号码,但我需要移动用户存储的地址。

感谢。

1 个答案:

答案 0 :(得分:0)

您可以使用它来获取完整地址

String addrWhere = ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?"; 
    String[] addrWhereParams = new String[]{id, 
        ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE}; 
    Cursor addrCur = cr.query(ContactsContract.Data.CONTENT_URI, 
                null, where, whereParameters, null); 
    while(addrCur.moveToNext()) {
        String poBox = addrCur.getString(
                     addrCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.POBOX));
        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));
        String type = addrCur.getString(
                     addrCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.TYPE));
    } 
    addrCur.close();