Retrieve Contact Phone Number From URI in Android

后端 未结 2 1205
离开以前
离开以前 2020-11-29 09:01

I am trying to get the contact\'s phone number after I have retrieved their ID number from the built-in activity. However, whenever I query the database using the cursor in

2条回答
  •  感动是毒
    2020-11-29 09:16

    I found the answer.

    The reason I was not getting any rows from the cursor was because I was using the line

    ContactsContract.CommonDataKinds.Phone.CONTACT_ID
    

    "The id of the row in the Contacts table that this data belongs to."

    Since I was getting the URI from contacts table anyways -- this was not needed and the following should have been substituted. The ID was the one corresponding to the contact in the phone table not the raw contact.

    ContactsContract.CommonDataKinds.Phone._ID
    

    Exchanging the lines returned the correct results in the query. Everything seems to be working well at the moment.

提交回复
热议问题