Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Health Connect permissions issue: Detecting user denial after twice rejecting permission request

I am implementing Health Connect in my Android app and using PermissionController.createRequestPermissionResultContract() to request permissions. The permissions request works fine when the user grants access. However, if the user denies permissions twice, the requestPermissions.launch(mViewModel.permissions) call no longer works.

I want to detect when the user initially denies permissions upon entering the screen and handle it appropriately. Here's a simplified version of my current implementation:

 `private val requestPermissionActivityContract =
        PermissionController.createRequestPermissionResultContract()

private var disconnectHealthConnectBottomSheet: DisconnectHealthConnectBottomSheet? = null

val requestPermissions =
        registerForActivityResult(requestPermissionActivityContract) { granted ->
        mViewModel.checkHealthConnectPermissions(grantedPermissions = granted)
    }

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    requestPermissions.launch(mViewModel.permissions)
}`

Issue:

After the user denies permissions twice, the requestPermissions.launch(mViewModel.permissions) does not trigger any response. I need a way to:

  1. Detect if the user has denied permissions when they return to the screen.

  2. Handle this scenario by guiding the user to enable permissions manually if needed.

What I’ve Tried:

I have implemented the checkHealthConnectPermissions method in my ViewModel to verify the granted permissions. However, it does not address the case where the user has denied permissions previously.

like image 274
Sudheer Karna Avatar asked Sep 30 '25 10:09

Sudheer Karna


1 Answers

According to the documentation, there is no callback for when a user denies the Health Connect permission twice. We need to display a custom button that redirects the user to the Health Connect settings.

val requestPermissions =
        registerForActivityResult(requestPermissionActivityContract) { granted -> 
            mViewModel.checkHealthConnectPermissions(
                grantedPermissions = granted
            )

            //Update Permission Request Count
            if (granted.isEmpty()) {
              ShowCustomButton()
            }
        }
like image 84
Sudheer Karna Avatar answered Oct 02 '25 06:10

Sudheer Karna



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!