Takeshi Hagikura | 5d1466d | 2016-03-01 18:20:15 +0900 | [diff] [blame] | 1 | <?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 Johns | 033b104 | 2017-03-22 11:30:08 -0700 | [diff] [blame^] | 20 | <group>Content</group> <!-- This field will be deprecated in the future |
Takeshi Hagikura | 5d1466d | 2016-03-01 18:20:15 +0900 | [diff] [blame] | 21 | and replaced with the "categories" tags below. --> |
| 22 | <package>com.example.android.scopeddirectoryaccess</package> |
| 23 | |
Trevor Johns | f9872de | 2016-06-15 09:52:40 -0700 | [diff] [blame] | 24 | <minSdk>24</minSdk> |
| 25 | <compileSdkVersion>24</compileSdkVersion> |
| 26 | <targetSdkVersion>24</targetSdkVersion> |
Takeshi Hagikura | 5d1466d | 2016-03-01 18:20:15 +0900 | [diff] [blame] | 27 | |
| 28 | <!-- Include additional dependencies here.--> |
Trevor Johns | 50c3316 | 2016-06-17 11:58:55 -0700 | [diff] [blame] | 29 | <dependency>com.android.support:recyclerview-v7:24.0.0</dependency> |
| 30 | <dependency>com.android.support:support-v4:24.0.0</dependency> |
Takeshi Hagikura | 5d1466d | 2016-03-01 18:20:15 +0900 | [diff] [blame] | 31 | |
| 32 | <template src="base" /> |
| 33 | |
| 34 | <strings> |
| 35 | <intro> |
| 36 | <![CDATA[ |
| 37 | This sample demonstrates how to use the Scoped Directory Access API introduced in Android N |
| 38 | to easily access to specific directories such as Pictures, Downloads instead of requesting |
| 39 | READ_EXTERNAL_STORAGE or WRITE_EXTERNAL_STORAGE in your manifest. |
| 40 | ]]> |
| 41 | </intro> |
| 42 | </strings> |
| 43 | |
| 44 | <metadata> |
Trevor Johns | dea5446 | 2016-03-08 15:50:43 -0800 | [diff] [blame] | 45 | <status>PUBLISHED</status> |
Trevor Johns | 033b104 | 2017-03-22 11:30:08 -0700 | [diff] [blame^] | 46 | <categories>Content</categories> |
Takeshi Hagikura | 5d1466d | 2016-03-01 18:20:15 +0900 | [diff] [blame] | 47 | <technologies>Android</technologies> |
| 48 | <languages>Java</languages> |
| 49 | <solutions>Mobile</solutions> |
| 50 | <level>BEGINNER</level> |
| 51 | <icon>screenshots/icon-web.png</icon> |
| 52 | <screenshots> |
| 53 | <img>screenshots/1.png</img> |
| 54 | <img>screenshots/2.png</img> |
| 55 | <img>screenshots/3.png</img> |
| 56 | </screenshots> |
| 57 | <api_refs> |
| 58 | <android>android.os.storage.StorageManager</android> |
| 59 | <android>android.os.storage.StorageVolume</android> |
| 60 | </api_refs> |
| 61 | |
| 62 | <description> |
| 63 | <![CDATA[ |
| 64 | This sample demonstrates how to use the Scoped Directory Access API introduced in Android N |
| 65 | to easily access to specific directories such as Pictures, Downloads instead of requesting |
| 66 | READ_EXTERNAL_STORAGE or WRITE_EXTERNAL_STORAGE in your manifest. |
| 67 | ]]> |
| 68 | </description> |
| 69 | |
| 70 | <!-- Multi-paragraph introduction to sample, from an educational point-of-view. |
| 71 | Makrdown formatting allowed. This will be used to generate a mini-article for the |
| 72 | sample on DAC. --> |
| 73 | <intro> |
| 74 | <![CDATA[ |
| 75 | This sample demonstrates how to use the Scoped Directory Access API that provides easy way to |
| 76 | access specific directories instead of: |
| 77 | - Requesting READ_EXTERNAL_STORAGE or WRITE_EXTERNAL_STORAGE in your manifest, which allows |
| 78 | access to all public directories on external storage. |
| 79 | - Using the Storage Access Framework, where the user usually picks directories via a System UI, |
| 80 | which is unnecessary if you app always accesses to the same external directory. |
| 81 | |
| 82 | To access to a specific directory, use a new Intent created using the StorageVolume class like |
| 83 | following: |
| 84 | |
| 85 | ``` |
| 86 | StorageManager sm = getSystemService(StorageManager.class); |
| 87 | StorageVolume volume = sm.getPrimaryVolume(); |
| 88 | Intent intent = volume.createAccessIntent(Environment.DIRECTORY_PICTURES); |
| 89 | startActivityForResult(intent, request_code); |
| 90 | ``` |
| 91 | |
| 92 | Note that the argument passed to StorageVolume.createAccessIntent needs to be one of the |
| 93 | values of Environment.DIRECTORY_\*. |
| 94 | |
| 95 | Once the user grants the access, `onActivityResult` override will be called with a |
| 96 | result code of `Activity.RESULT_OK` and an intent data that contains the URI representing |
| 97 | the directory. |
| 98 | ]]> |
| 99 | </intro> |
| 100 | </metadata> |
| 101 | </sample> |