With security awareness on the rise, users are becoming more skeptical about allowing apps to have unnecessary permissions. Android N introduces a new option called Scoped Directory Access, allowing your application to request access to only the required permissions, instead of general access to all folders.
If your application requests READ_EXTERNAL_STORAGE
and/or WRITE_EXTERNAL_STORAGE
permission, but only needs access to a specific directory, you can use Scoped Directory access instead. This recipe will demonstrate how to request access to a specific directory, the Music
folder in this case.
Create a new project in Android Studio and call it ScopedDirectoryAccess
.In the Target Android Device
dialog, be sure to select API 24: Android 7.0 (Nougat)
or higher for the Phone & Tablet
option. Select Empty Activity
on the Add an Activity to Mobile
dialog.