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)
}`
After the user denies permissions twice, the requestPermissions.launch(mViewModel.permissions)
does not trigger any response. I need a way to:
Detect if the user has denied permissions when they return to the screen.
Handle this scenario by guiding the user to enable permissions manually if needed.
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.
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()
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With