Search code examples
androidkotlinandroid-permissions

Check permission always return denied


I was asking for WRITE_EXTERNAL_STORAGE permission with the following statement

ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), PERMISSION_WRITE)

This was working...until now. In the method onRequestPermissionsResult, grantResults always contains -1

override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String?>, grantResults: IntArray) {
    
    super.onRequestPermissionsResult(requestCode, permissions, grantResults)
    if (requestCode == PERMISSION_WRITE) {
        if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

            Timber.i("PERMISSION GRANTED")
        } else {

            showSettingsDialog()
        }
    }
}

Also, I have the uses-permission in the manifest

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

The thing is, if I go to the app settings the permission appears as granted but from the app it always return is not granted.

I tried deleting build folders because none has changed and this was working fine for a week

Any idea about what can I test?

best regards


Solution

  • It seems a bug in android 10, so you can replace the permission in manifest with:

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:node="replace"/>