2015-09-26 91 views
0

我使用下面的代碼從聯繫人中獲取號碼,但我仍然獲取聯繫人的手機號碼。從聯繫人中獲取地址但仍然收到號碼?

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(); 
    } 

在烤麪包片我得到一個聯繫人的手機號碼,但我需要的是移動用戶存儲的地址。

謝謝。

+0

你需要'ContactsContract.CommonDataKinds.StructuredPostal#CONTENT_URI'作爲'Uri' – pskink

回答

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(); 
相關問題