Challenge: Another Implicit Intent -- HELP!

Has anyone been able to solve this challenge? I’m able to get the contact ID from ContactsContract.Contacts._ID but struggling to find out how to use it to retrieve the contact’s phone number. Would appreciate your assistance!

Without giving the entire solution, there are a few additional steps that need to be taken for this challenge plus some research to determine the underlying structure.

First, runtime permissions need to be checked to read the Contacts information. The Contact’s name is not considered sensitive information so the Contacts app lends the permissions to retrieve a name. However, the Contact’s phone number is sensitive so the user must give this dangerous permission explicitly to your app.

Next, some knowledge of the Contacts database table is required to make the correct query. Once you have the Contacts._ID, you then need to make an additional query to get the phone number. This involves setting up another cursor to step through the result. To save you some of the research digging through the documentation, here is the query to be performed:

val phoneURI = ContactsContract.CommonDataKinds.Phone.CONTENT_URI
val phoneNumberQueryFields = listOf(ContactsContract.CommonDataKinds.Phone.NUMBER )
val phoneWhereClause = "${ContactsContract.CommonDataKinds.Phone.CONTACT_ID} = ?"
val phoneQueryParameters = listOf( contactID.toString() )
val phoneCursor = requireActivity()
        .contentResolver
        .query(phoneURI, 
               phoneNumberQueryFields.toTypedArray(), 
               phoneWhereClause, 
               phoneQueryParameters.toTypedArray(), 
               null)

Hi jpaone,

thanks for your reply, but in this solution we get the number just in the moment of picking the suspect, not after that?

e.g: we pick a suspect from our contact list -> his name get displayed in the suspect button-> we close the CrimeFragment and reopen it , now if we click the call button nothing will happen because we dont have the suspect’s phone number

i thik that we need to create another field in our database to store the _ID to retrieve the phone later

Correct, the steps I outlined was just to retrieve the phone number when a contact is selected. You could store that in the database.

Or if not wanting to store the field n your database then if a suspect is already selected requery the contacts database for the most current phone number.