File storage on Android has been a complicated subject over the years. It started very simply with private folders for each app and a pair of permissions for read and write access to just about everything else. The seeds of change were planted with Honeycomb when Google quietly closed off write access to secondary storage like SD cards, but most people didn't take notice until Google insisted OEMs enforce the same rules in KitKat.

New APIs have been introduced in each year since with the goal to give developers new ways to work with the filesystem — or abstract it from view — while also improving security and maintaining privacy. Android N continues this momentum with a new API called Scoped Directory Access aimed at giving users more control through Marshmallow-style permission requests.

The Scoped Directory Access API provides a simple process for requesting access to any of the system-defined media and content folders like /Pictures and /Downloads. When a request is made, the operating system checks if the app has already been granted access to that folder. If the user hasn't authorized it in the past, a dialog appears to prompt the user to allow access, much like the runtime permission prompts introduced in Android Marshmallow.

At this time, the API supports requests for ten directories, including: /Music, /Podcasts, /Ringtones, /Alarms, /Notifications, /Pictures, /Movies, /Downloads, /DCIM, and /Documents.

Sample permission request dialog.

Once permission is granted to a folder, an app is free to read and write to it without prompting the user again. Access to a folder also grants access to all files and folders within. Access is also granted across removable media like SD cards and USB drives in situations where a device allows multiple instances of a particular folder. Scoped Directory Access is tailored to be the best solution for apps like photo viewers, music players, and text editors.

One small advantage of Scoped Directory Access API is that it doesn't require the use of older permissions. This means developers may be able to exclude READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE – but only if the app doesn't support versions prior to Android N. Granted, that won't matter to most apps for a few years, but developers can still set a maxSdkVersion parameter on permissions that are not required above a certain API level, which makes it an ideal option for reducing the number of required permissions.

If you're looking to implement Scoped Directory Access in your app, check out the developer page with more details and best practices.

In Android N, apps can use new APIs to request access to specific external storage directories, including directories on removable media such as SD cards. The new APIs greatly simplify how your application accesses standard external storage directories, such as the Pictures directory. Apps like photo apps can use these APIs instead of using READ_EXTERNAL_STORAGE, which grants access to all storage directories, or the Storage Access Framework, which makes the user navigate to the directory.

Additionally, the new APIs simplify the steps a user takes to grant external storage access to your app. When you use the new APIs, the system uses a simple permissions UI that clearly details what directory the application is requesting access to.

For more information, see the Scoped Directory Access developer documentation.

Quoted from: N Preview Overview

Source: N Preview Overview and Documentation