R Raw Paths and All Files Access

In R DP1, I could not get the “raw paths” feature or the “all files access” feature to work.

In R DP2, both seem to be working fine.

The documentation is a bit confusing, but here is what I have seen in light experimentation.

Raw Paths

UPDATE 2020-05-16: The material in this section is out of date. Please see this updated post for updated information.

In a nutshell, READ_EXTERNAL_STORAGE works like it did from Android 4.4 through Android 9. If you request it, and the user grants it, you can traverse external storage more or less as you were used to.

However, there are caveats:

  • The documentation mentions reduced performance. I have not attempted to do any sort of apples-to-apples comparison, but I don’t get the sense that the performance degradation is severe.

  • As the documentation notes, you still do not have access to Android/ and its subdirectories.

  • I have not tried removable storage.

  • While the documentation emphasizes native libraries, read access works fine from Java/Kotlin. I have not tried native library access, but I assume that it works.

Also, methods like getExternalStorageDirectory() and getExternalStoragePublicDirectory() on Environment are still deprecated. My guess is that we are supposed to use getDirectory() on StorageVolume, as that was added in Android R. I have not experimented with that yet. getExternalStorageDirectory() works, at least on R DP2, returning the conventional location.

All Files Access


If you request MANAGE_EXTERNAL_STORAGE in the manifest, and you use Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION to bring up the Settings screen for this, and the user grants the permission, then you can write content to external storage. The effect is akin to what we had from Android 4.4 through Android 9.

Again, though, there are caveats:

  • The same concerns exist around how we get the filesystem path to use.

  • Presumably, write performance is also reduced.

  • Even with this permission, you still do not have access to Android/ and its subdirectories.

  • I still have not tried removable storage (hey, I’ve been busy writing this blog post).

  • There is no obvious means to find out if we hold this permission. It is not a dangerous permission, so checkSelfPermission() does not work. The issue has been marked as “fixed”, but I did not notice a method for this in DP2, so perhaps the method will show up in a later developer preview.

Now What?

Given last year’s continuous changes in this area in the Q developer previews, I am not making any final recommendations until R ships as Android 11.

Also, the fact that filesystem-style access is back in R does not change the fact that we should be losing that access in Q. android:requestLegacyExternalStorage is supposed to be ignored by Android 10 once our targetSdkVersion hits 29. Assuming that remains the case (I have not re-tested it), then we still lack filesystem-style access in Android 10, even though we have it in 9 and 11. If so, you are still going to be needing to try to adopt the Storage Access Framework and/or the MediaStore to handle Android 10. Plus, the MANAGE_EXTERNAL_STORAGE permission screen is decidedly more scary-looking than the normal dangerous permission dialog, so fewer users will be willing to grant it.

So, I’ll be watching this area in DP3 and beyond, to see what changes, if anything. However, it looks like external storage is making a comeback, after I left it for dead almost exactly one year ago.

Interested in Jetpack Compose? jetc.dev has a weekly newsletter of the latest articles, samples, and other details of Compose development!