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