运行时权限检查后,回收器视图数据未显示



我似乎不知道如何在运行时允许权限按钮按下后显示数据。数据处于回收器视图

权限对话框工作正常,因为这给了我正确的结果,但我似乎无法在移动设备上获得数据

代码如下:

private val requestMultiplePermissions =registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { permissions ->
if (permissions[READ_EXTERNAL_STORAGE] == true && permissions[WRITE_EXTERNAL_STORAGE] == true) {
getMusicList()
} else {
checkPermissions()
Log.d(TAG, "Permission not granted")
}
}

private fun checkPermissions(){
if (context?.let {
ContextCompat.checkSelfPermission(
it,
READ_EXTERNAL_STORAGE
)
} != PackageManager.PERMISSION_GRANTED) {
requestMultiplePermissions.launch(
arrayOf(READ_EXTERNAL_STORAGE, WRITE_EXTERNAL_STORAGE))
}
else {
requestMultiplePermissions
}
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,savedInstanceState: Bundle?): View {

checkPermissions()
}

private fun checkPermissions() {
if (context?.let {
ContextCompat.checkSelfPermission(
it,
READ_EXTERNAL_STORAGE
)
} != PackageManager.PERMISSION_GRANTED) {
requestMultiplePermissions.launch(
arrayOf(READ_EXTERNAL_STORAGE, WRITE_EXTERNAL_STORAGE))
} else {
//requestMultiplePermissions
getMusicList()
}
}

被授予权限后不需要再次请求

相关内容

  • 没有找到相关文章

最新更新