checkSelfPermission returns PERMISSION_GRANTED in Android 10 but permission denied-ThrowExceptions

Exception or error:

I am calling ActivityCompat.checkSelfPermission(activity, "android.permission.WRITE_EXTERNAL_STORAGE") on a directory returned by Environment.getExternalStorageDirectory(). Interestingly, checkSelfPermission returns PERMISSION_GRANTED but when I try to write to the storage, I get permission denied. This happens only in API level 29. In API 28 or less, everything works as expected. Why does checkSelfPermission return GRANTED but it is actually not granted?

How to solve:

And on Android 10 file paths outside of your App’s private directories are worthless.

Going forward it is probably best just to use Media Store or Storage Access Framework

The reason why is that permission is still used see see table but only for the MediaStore API

Leave a Reply

Your email address will not be published. Required fields are marked *