该问题可能是由于缺少必要的请求权限导致的。为了确保请求权限正常工作,可以按照以下步骤进行操作:
LaunchedEffect { PermissionsRequester( permission = android.Manifest.permission.WRITE_EXTERNAL_STORAGE, requestCode = 100 ) { result -> if (result) { // Permission was granted } else { // Permission denied } } }
class MainActivity : AppCompatActivity() { private val permissionLauncher = registerForActivityResult(ActivityResultContracts.RequestPermission()) { isGranted -> if (isGranted) { // Permission was granted } else { // Permission denied } }
override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array,
grantResults: IntArray
) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
// Forward results to permission launcher
permissionLauncher.launch(permissions[0])
}
}
通过上述步骤,您可以确保Android Jetpack Accompanist中的权限请求正常工作。