1
2Android ScopedDirectoryAccess Sample
3===================================
4
5This sample demonstrates how to use the Scoped Directory Access API introduced in Android N
6to easily access to specific directories such as Pictures, Downloads instead of requesting
7READ_EXTERNAL_STORAGE or WRITE_EXTERNAL_STORAGE in your manifest.
8
9Introduction
10------------
11
12This sample demonstrates how to use the Scoped Directory Access API that provides easy way to
13access specific directories instead of:
14 - Requesting READ_EXTERNAL_STORAGE or WRITE_EXTERNAL_STORAGE in your manifest, which allows
15   access to all public directories on external storage.
16 - Using the Storage Access Framework, where the user usually picks directories via a System UI,
17   which is unnecessary if you app always accesses to the same external directory.
18
19To access to a specific directory, use a new Intent created using the StorageVolume class like
20following:
21
22```
23StorageManager sm = getSystemService(StorageManager.class);
24StorageVolume volume = sm.getPrimaryVolume();
25Intent intent = volume.createAccessIntent(Environment.DIRECTORY_PICTURES);
26startActivityForResult(intent, request_code);
27```
28
29Note that the argument passed to StorageVolume.createAccessIntent needs to be one of the
30values of Environment.DIRECTORY_\*.
31
32Once the user grants the access, `onActivityResult` override will be called with a
33result code of `Activity.RESULT_OK` and an intent data that contains the URI representing
34the directory.
35
36Pre-requisites
37--------------
38
39- Android SDK 24
40- Android Build Tools v27.0.2
41- Android Support Repository
42
43Screenshots
44-------------
45
46<img src="screenshots/1.png" height="400" alt="Screenshot"/> <img src="screenshots/2.png" height="400" alt="Screenshot"/> <img src="screenshots/3.png" height="400" alt="Screenshot"/>
47
48Getting Started
49---------------
50
51This sample uses the Gradle build system. To build this project, use the
52"gradlew build" command or use "Import Project" in Android Studio.
53
54Support
55-------
56
57- Google+ Community: https://plus.google.com/communities/105153134372062985968
58- Stack Overflow: http://stackoverflow.com/questions/tagged/android
59
60If you've found an error in this sample, please file an issue:
61https://github.com/googlesamples/android-ScopedDirectoryAccess
62
63Patches are encouraged, and may be submitted by forking this project and
64submitting a pull request through GitHub. Please see CONTRIBUTING.md for more details.
65
66License
67-------
68
69Copyright 2017 The Android Open Source Project, Inc.
70
71Licensed to the Apache Software Foundation (ASF) under one or more contributor
72license agreements.  See the NOTICE file distributed with this work for
73additional information regarding copyright ownership.  The ASF licenses this
74file to you under the Apache License, Version 2.0 (the "License"); you may not
75use this file except in compliance with the License.  You may obtain a copy of
76the License at
77
78http://www.apache.org/licenses/LICENSE-2.0
79
80Unless required by applicable law or agreed to in writing, software
81distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
82WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
83License for the specific language governing permissions and limitations under
84the License.
85