Scoped storage in Android 11

Rahul Sharma
1 min readApr 11, 2020

Why we need scoped ?

For now if we are giving read/write access to any application than that app have full access to storage, that mean there is no privacy on data. To overcome this privacy issue Scoped Storage came into the picture where user know the path which is share or have permission to particular application.

Actually android was launching scoped storage in android 10 but majority of developers and application was not ready for this change. So, android gave legacy support for android 10

target sdk is android 10

android:requestLegacyExternalStorage=”true”

above piece of code should be added to AndroidManifest inside application to tell android that we still wants to use legacy way of storage.

Now if your app is targeting android 11 and you want to migrate the old storage data to scoped storage then there is a different attribute

(target sdk is android 11)

android:preserveLegacyExternalStorage = "true"

For file picker you can use some

android.os.Environment

public static String DIRECTORY_ALARMS = "Alarms";
public static String DIRECTORY_DCIM = "DCIM";
public static String DIRECTORY_DOCUMENTS = "Documents";
public static String DIRECTORY_DOWNLOADS = "Download";
public static String DIRECTORY_MOVIES = "Movies";
public static String DIRECTORY_MUSIC = "Music";
public static String DIRECTORY_NOTIFICATIONS = "Notifications";
public static String DIRECTORY_PICTURES = "Pictures";
public static String DIRECTORY_PODCASTS = "Podcasts";
public static String DIRECTORY_RINGTONES = "Ringtones";

If you want complete example on scoped storage please let me know if comments.

--

--