Android contacts Display Name and Phone Number(s) in single database query?

前端 未结 3 1701
被撕碎了的回忆
被撕碎了的回忆 2020-11-27 11:12

I\'m trying to obtain a list of contacts from the native database with their Display Name and Phone Number (any or all). There are many methods for obtaining this informatio

3条回答
  •  情深已故
    2020-11-27 11:39

    The contacts API is extremly tricky and has several implicit joins.

    Read the ContactContract and ContactsProvider2 if you can afford the time.

    What do you want? The tables are chained like this:

    • Contact 1--* Raw Contact
    • Raw Contact 1--* Phone Number (data table)

    The API works like this: you select the bottom-most element (a phone number) and implicit join to the topmost element (contact).

    You want to use the PHONE URI case (ContactsProvider2 / line 4377). This should select all phone numbers and join up to the contact.

    Combine the PHONE uri with some UI magic (for grouping), request the DISPLAY_NAME and the PHONE number (DATA1?) and you should be able to solve the problem.

提交回复
热议问题