问题描述
应如何实现向 Jetpack Compose View 请求许可?我正在尝试使用 Jetpack Compose 实现访问相机的应用程序.我尝试了 How to get Current state or context inJetpack Compose 不幸的是示例不再适用于 dev06.
How should be implemented requesting permission from Jetpack Compose View? I'm trying implement application accessing Camera with Jetpack Compose. I tried example from How to get Current state or context in Jetpack Compose Unfortunately example is no longer working with dev06.
fun hasPermissions(context: Context) = PERMISSIONS_REQUIRED.all {
ContextCompat.checkSelfPermission(context, it) == PackageManager.PERMISSION_GRANTED
}
}
}
推荐答案
查看 Google Accompanist 的 Jetpack Compose 权限.
Check out Google Accompanist's Jetpack Compose Permissions.
请记住,在撰写本文时,该 API 仍被认为是实验性的,并且在使用时需要 @ExperimentalPermissionsApi
注释.
Bear in mind that, at the time of writing, the API is still considered experimental and will require the @ExperimentalPermissionsApi
annotation when used.
- 文档和用法:https://google.github.io/accompanist/permissions/
- 示例:https://github.com/google/accompanist/tree/main/sample/src/main/java/com/google/accompanist/sample/permissions
这篇关于如何使用 Jetpack Compose 请求权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!