tw-S
tw-S

Reputation: 1217

checkSelfPermission returns PERMISSION_GRANTED in Android 10 but permission denied

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?

Upvotes: 0

Views: 153

Answers (1)

Andrew
Andrew

Reputation: 10162

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

https://developer.android.com/training/data-storage/shared

The reason why is that permission is still used see see table https://developer.android.com/training/data-storage but only for the MediaStore API

Upvotes: 1

Related Questions