Android; I only have 2 contacts, yet I can obtain 5 from a query, why?

前端 未结 3 901
-上瘾入骨i
-上瘾入骨i 2020-12-22 06:54

I have setup 2 test contacts in my emulator.

I\'m running the following query, it should pick them both out, populate my domain object, and add to a list. The output

3条回答
  •  时光取名叫无心
    2020-12-22 07:31

    You are querying ContactsContract.Data, which is a generic container that holds a list of various contact details, such as phone numbers, postal codes etc.. You must filter the results for the rows whose ContactsContract.Data.MIMETYPE column equals StructuredPostal.CONTENT_ITEM_TYPE:

    So change the query to:

    Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI,
         null, null, ContacsContract.Data.MIMETYPE +  "='" + 
    ContactsContract.StructuredPostal.CONTENT_ITEM_TYPE + "'", null);
    

    See ContactsContract.Data

提交回复
热议问题