Get all contacts and their details (e.g. postal address) in one OUTER JOIN query

前端 未结 2 947
半阙折子戏
半阙折子戏 2021-01-20 16:18

I know how to retrieve contact data for specific contacts. However, i can\'t find a way to get all contacts plus some of their details in a single query. The following code

相关标签:
2条回答
  • 2021-01-20 16:28

    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();                   
    
    0 讨论(0)
  • 2021-01-20 16:37

    All contact information in Android 2.0 is stored in a single database table. So you can get all the information you need in a single query:

    Cursor c = getContentResolver().query(ContactsContract.Data.CONTENT_URI,
        null, null, null, sortOrder);
    

    The just iterate through the data and check Data.MIMETYPE column. For example, if this column has StructuredPostal.CONTENT_ITEM_TYPE value, then you can get StructuredPostal fields from this column.

    0 讨论(0)
提交回复
热议问题