blob: db7bcbca64b0d1665db0bf6b1a79d753f1e25bbe [file] [log] [blame]
Takeshi Hagikura5d1466d2016-03-01 18:20:15 +09001<?xml version="1.0" encoding="UTF-8"?>
2<!--
3 Copyright 2016 The Android Open Source Project
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16-->
17
18<sample>
19 <name>ScopedDirectoryAccess</name>
Trevor Johns033b1042017-03-22 11:30:08 -070020 <group>Content</group> <!-- This field will be deprecated in the future
Takeshi Hagikura5d1466d2016-03-01 18:20:15 +090021 and replaced with the "categories" tags below. -->
22 <package>com.example.android.scopeddirectoryaccess</package>
23
Trevor Johnsf9872de2016-06-15 09:52:40 -070024 <minSdk>24</minSdk>
Felipe Leme8450ba92018-01-08 14:04:52 -080025 <compileSdkVersion>27</compileSdkVersion>
Trevor Johnsf9872de2016-06-15 09:52:40 -070026 <targetSdkVersion>24</targetSdkVersion>
Takeshi Hagikura5d1466d2016-03-01 18:20:15 +090027
28 <!-- Include additional dependencies here.-->
Felipe Leme8450ba92018-01-08 14:04:52 -080029 <dependency>com.android.support:recyclerview-v7:27.0.2</dependency>
Takeshi Hagikura5d1466d2016-03-01 18:20:15 +090030
31 <template src="base" />
32
33 <strings>
34 <intro>
35<![CDATA[
36This sample demonstrates how to use the Scoped Directory Access API introduced in Android N
37to easily access to specific directories such as Pictures, Downloads instead of requesting
38READ_EXTERNAL_STORAGE or WRITE_EXTERNAL_STORAGE in your manifest.
39]]>
40 </intro>
41 </strings>
42
43 <metadata>
Trevor Johnsdea54462016-03-08 15:50:43 -080044 <status>PUBLISHED</status>
Trevor Johns033b1042017-03-22 11:30:08 -070045 <categories>Content</categories>
Takeshi Hagikura5d1466d2016-03-01 18:20:15 +090046 <technologies>Android</technologies>
47 <languages>Java</languages>
48 <solutions>Mobile</solutions>
49 <level>BEGINNER</level>
50 <icon>screenshots/icon-web.png</icon>
51 <screenshots>
52 <img>screenshots/1.png</img>
53 <img>screenshots/2.png</img>
54 <img>screenshots/3.png</img>
55 </screenshots>
56 <api_refs>
57 <android>android.os.storage.StorageManager</android>
58 <android>android.os.storage.StorageVolume</android>
59 </api_refs>
60
61 <description>
62<![CDATA[
63This sample demonstrates how to use the Scoped Directory Access API introduced in Android N
64to easily access to specific directories such as Pictures, Downloads instead of requesting
65READ_EXTERNAL_STORAGE or WRITE_EXTERNAL_STORAGE in your manifest.
66]]>
67 </description>
68
69 <!-- Multi-paragraph introduction to sample, from an educational point-of-view.
70 Makrdown formatting allowed. This will be used to generate a mini-article for the
71 sample on DAC. -->
72 <intro>
73<![CDATA[
74This sample demonstrates how to use the Scoped Directory Access API that provides easy way to
75access specific directories instead of:
76 - Requesting READ_EXTERNAL_STORAGE or WRITE_EXTERNAL_STORAGE in your manifest, which allows
77 access to all public directories on external storage.
78 - Using the Storage Access Framework, where the user usually picks directories via a System UI,
79 which is unnecessary if you app always accesses to the same external directory.
80
81To access to a specific directory, use a new Intent created using the StorageVolume class like
82following:
83
84```
85StorageManager sm = getSystemService(StorageManager.class);
86StorageVolume volume = sm.getPrimaryVolume();
87Intent intent = volume.createAccessIntent(Environment.DIRECTORY_PICTURES);
88startActivityForResult(intent, request_code);
89```
90
91Note that the argument passed to StorageVolume.createAccessIntent needs to be one of the
92values of Environment.DIRECTORY_\*.
93
94Once the user grants the access, `onActivityResult` override will be called with a
95result code of `Activity.RESULT_OK` and an intent data that contains the URI representing
96the directory.
97]]>
98 </intro>
99 </metadata>
100</sample>