Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

permissionsController.openAppSettings() isn't working tried on android emulator #90

Open
shahid-nadi opened this issue Nov 3, 2023 · 0 comments

Comments

@shahid-nadi
Copy link

shahid-nadi commented Nov 3, 2023

When permission is denied i am trying to open the setting page but it's working

val factory: PermissionsControllerFactory = rememberPermissionsControllerFactory()
val viewModel = PermissionViewModel(factory.createPermissionsController()) BindEffect(viewModel.permissionsController)

viewModel.askPermission(Permission.COARSE_LOCATION)

Viewmodel code

private val _permissionState = MutableStateFlow(Pair(Permission.COARSE_LOCATION, PermissionState.NotDetermined))
val permissionState = _permissionState.asStateFlow()

`fun askPermission(permission: Permission) {
    viewModelScope.launch {
        try {
            val grantState = permissionsController.getPermissionState(permission)
            when (grantState) {
                PermissionState.Granted -> {
                    println("askPermission Granted ")
                    _permissionState.emit(Pair(permission, PermissionState.Granted))
                }
                PermissionState.DeniedAlways -> {
                    println("askPermission DeniedAlways")
                    permissionsController.openAppSettings()
                }

                PermissionState.NotDetermined,
                PermissionState.Denied,
                -> {
                    println("askPermission Denied ")
                     permissionsController.providePermission(permission)
                }
            }
        } catch (deniedAlways: DeniedAlwaysException) {
            // Permission is always denied.
            println("deniedAlways")
            _permissionState.emit(Pair(permission, PermissionState.DeniedAlways))
        } catch (denied: DeniedException) {
            // Permission was denied.
            println("denied")
            _permissionState.emit(Pair(permission, PermissionState.Denied))
        } catch (exception: Exception) {
            println("exception")
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant