Is there any way to ask run-time permissions for K...
# multiplatform
h
Is there any way to ask run-time permissions for KMP projects ?
f
https://github.com/icerockdev/moko-permissions seems ok. works for iOS/Android For desktop/web I don’t know
h
Thanks a lot @François will explore it.
Do they support to kotlin version 2 ? look like they are current supporting kotlin 1.9.10
f
it’s working on version2
👀 1
h
below is my permission viewmodel code
Copy code
class PermissionVm(private val controller: PermissionsController) : ViewModel() {
    var state by mutableStateOf(PermissionState.NotDetermined)
        private set

    init {
        viewModelScope.launch {
            state = controller.getPermissionState(Permission.GALLERY)
        }
    }

    fun provideOrRequestGalleryPermissions() {
        viewModelScope.launch {
            try {
                controller.providePermission(Permission.GALLERY)
                state = PermissionState.Granted
                Logger.e("Request Permissions state granted")
            } catch (ex: DeniedAlwaysException) {
                state = PermissionState.DeniedAlways
                Logger.e("Request Permissions state DeniedAlways ")
            } catch (ex: DeniedException) {
                state = PermissionState.Denied
                Logger.e("Request Permissions state denied ")
            } catch (ex: RequestCanceledException) {
                Logger.e("Request Permissions Exception ${ex.message}")
            } catch (ex: Exception) {
                Logger.e("Request Permissions Exception ${ex.message}")
            }
        }
    }
}
When I grant permission still this showing
Copy code
DeniedAlways
can you please help me here why that so and this is my composable method
Copy code
@Composable
fun CheckAndRequestPermissions(
    permissionVm: PermissionVm,
    controller: PermissionsController,
    navHostContent: NavHostContent,
    doaClient: KtorClient
) {
    Column(
        modifier = Modifier.fillMaxSize(),
        verticalArrangement = Arrangement.Center,
        horizontalAlignment = Alignment.CenterHorizontally
    ) {
        when (permissionVm.state) {
            PermissionState.Granted -> {
                NavHostContainer(
                    navComponent = navHostContent,
                    doaClient = doaClient,
                    modifier = Modifier.fillMaxSize()
                )
            }

            PermissionState.DeniedAlways -> {
                CustomButton(
                    label = "App Settings",
                    txtColor = Color.White,
                    buttonColor = lightBlue,
                    onClick = {
                        controller.openAppSettings()
                    }
                )
            }

            else -> {
                CustomButton(
                    label = "Request Permissions",
                    txtColor = Color.White,
                    buttonColor = lightBlue,
                    onClick = {
                        permissionVm.provideOrRequestGalleryPermissions()
                    }
                )
            }
        }

    }

}
t
You can use my library if you want. It has permissions, storage, camera & video apis. Everything you need https://github.com/TheArchitect123/KmpEssentials
164 Views