Suspect Button always Disabled despite i have contacts app

everything is worked fine. until i added the (Checking for responding activities section)

the button remained disabled despite i have a contacts app and it was working fine already.

 suspectButton.apply{
            val pickContactIntent = Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI)
            setOnClickListener {
                startActivityForResult(pickContactIntent, REQUEST_CONTACT)
            }
 
            val packageManager : PackageManager = requireActivity().packageManager
            val resolvedActivity: ResolveInfo? =
                packageManager.resolveActivity(pickContactIntent ,
                    PackageManager.MATCH_DEFAULT_ONLY)

            if (resolvedActivity==null) {
                isEnabled = false
            }
        }

The one thing that i have is different from the book code is the null safety for URI, android studio forced me to do this way

val cursor = contactURI?.let {
                    requireActivity().contentResolver
                        .query(it, queryFields, null, null, null)
                }

because we had val contactURI : Uri? = data.data in the first place…

how to fix this?

2 Likes

okay. i found others posted about it…
how can i delete this post?