I make a permish request READ_EXTERNAL_STORAGE, confirm the result and try to get the contents of the directory
File(Environment.getExternalStoragePublicDirectory (Environment.DIRECTORY_DCIM).toString() + "/Camera").listFiles()
Everything works out, but if I do this sequence
Perm request -> rejection -> perm request again -> confirmation -> retrieving the contents of the directory
I get null
. But if I close the application and open it again (the permission remains confirmed), then everything works.
It seems that after refusal and subsequent confirmation, the system still returns null
in this session. And only after closing and opening it starts working correctly.
What am I doing wrong?
Who faced?
EDIT
Implementation in the perm request fragment
private fun checkPermission() { if (ActivityCompat.checkSelfPermission( activity!!, Manifest.permission.READ_EXTERNAL_STORAGE ) == PackageManager.PERMISSION_GRANTED ) { model.requestContent() } else { requestPermissions( arrayOf(android.Manifest.permission.READ_EXTERNAL_STORAGE), Constants.REQUEST_READ_EXTERNAL_STORAGE ) } } override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) { when (requestCode) { Constants.REQUEST_READ_EXTERNAL_STORAGE -> { grantResults.forEach { if (it != PackageManager.PERMISSION_GRANTED) { model.permissionDenied() return } } model.requestContent() } else -> super.onRequestPermissionsResult(requestCode, permissions, grantResults) } }