Reputation: 381
I understand why requestLegacyExternalStorage
is not working on Android 11 with API 30. However, it doesn't work for me on Android 11 when I am targeting to API 29.
Here are the code level differences I observed:
Method StorageManager::getStorageVolumes
was able to list all the volumes on Android 10 (both internal storage and external storage), but it only lists internal storage on Android 11.
We also tried File("/storage").listFiles()
, it returns null
which means this path doesn't exist.
My app is designed to browse files on external storages, now it stops working on Android 11 as we're not able to see the external storage for some reason.
Here is my AndroidManifest.xml
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:requestLegacyExternalStorage="true" >
...
Here is my build.gradle
compileSdkVersion 30
buildToolsVersion '30.0.1'
defaultConfig {
minSdkVersion 16
targetSdkVersion 29
...
I am wondering if there is anything I missed in order to use the legacy way to access external storages on Android 11.
Updated: @blackapps
File("/storage").listFiles()
returns a File
object of the external storage with path like /storage/981B-469E
, and we're allowed to list files in it.
Context.getExternalFilesDir()
returns a File
object with path like /storage/emulated/0/Android/data/com.xx.xx/files
Environment.getExternalStorageDirectory()
returns a File
object with path like /storage/emulated/0
I am not able to list files inside paths like /storage/emulated/0
.
Upvotes: 1
Views: 4349
Reputation: 31
Android 11 has removed scoped storage so, legacyExternalStorage
is only seen in Android 10, and ignored in Android 11, if you migrate back to Android 10 then it will work.
or use in AndroidManifest.xml
Manage_External_Storage= true
and ask for Access all file permission from user.
To overcome this situation, Google had given options to use other options, and nothing more is in their documentations.
Upvotes: 3