Closed lm136412110 closed 1 year ago
val requestList = ArrayList() if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { requestList.add(Manifest.permission.READ_MEDIA_IMAGES) requestList.add(Manifest.permission.READ_MEDIA_AUDIO) requestList.add(Manifest.permission.READ_MEDIA_VIDEO) requestList.add(Manifest.permission.WRITE_EXTERNAL_STORAGE) } if (requestList.isNotEmpty()) { PermissionX.init(this) .permissions(requestList) .onExplainRequestReason { scope, deniedList -> val message = "您同意以下权限才能选取照片" scope.showRequestReasonDialog(deniedList, message, "允许", "拒绝") } .request { allGranted, grantedList, deniedList -> if (allGranted) { Toast.makeText(this,"全部授权", Toast.LENGTH_SHORT).show() } else { Toast.makeText(this,"缺少权限$grantedList", Toast.LENGTH_SHORT).show() } } }
这个权限组添加WRITE_EXTERNAL_STORAGE进去,allGranted会一直返回false,要怎么处理? 我试了下取前三个权限+CAMERA权限,是没问题的。
WRITE_EXTERNAL_STORAGE 已经不用自己获取了吗?
val requestList = ArrayList()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
requestList.add(Manifest.permission.READ_MEDIA_IMAGES)
requestList.add(Manifest.permission.READ_MEDIA_AUDIO)
requestList.add(Manifest.permission.READ_MEDIA_VIDEO)
requestList.add(Manifest.permission.WRITE_EXTERNAL_STORAGE)
}
if (requestList.isNotEmpty()) {
PermissionX.init(this)
.permissions(requestList)
.onExplainRequestReason { scope, deniedList ->
val message = "您同意以下权限才能选取照片"
scope.showRequestReasonDialog(deniedList, message, "允许", "拒绝")
}
.request { allGranted, grantedList, deniedList ->
if (allGranted) {
Toast.makeText(this,"全部授权", Toast.LENGTH_SHORT).show()
} else {
Toast.makeText(this,"缺少权限$grantedList", Toast.LENGTH_SHORT).show()
}
}
}