Home | History | Annotate | Download | only in articles
      1 page.title=
      2 page.keywords=preview,sdk,scoped directory access
      3 page.tags=androidn
      4 
      5 @jd:body
      6 
      7 <div id="tb-wrapper">
      8 <div id="tb">
      9   <h2></h2>
     10   <ol>
     11     <li><a href="#accessing"></a></li>
     12     <li><a href="#removable"> </a></li>
     13     <li><a href="#best"> </a></li>
     14   </ol>
     15 </div>
     16 </div>
     17 
     18 <p><code>Pictures</code> 
     19 
     20 
     21 </p>
     22 
     23 <ul>
     24 <li> {@link android.Manifest.permission#READ_EXTERNAL_STORAGE}  {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} 
     25 
     26 
     27 </li>
     28 <li><a href="{@docRoot}guide/topics/providers/document-provider.html">  </a> UI 
     29 
     30 
     31 
     32 </li>
     33 </ul>
     34 
     35 <p>Android N   API 
     36  </p>
     37 
     38 <h2 id="accessing"></h2>
     39 
     40 <p><code>StorageManager</code> 
     41 <code>StorageVolume</code> 
     42 <code>StorageVolume.createAccessIntent()</code> 
     43   <code>StorageManager.getVolumesList()</code> 
     44 
     45 </p>
     46 
     47 <p>
     48 <code>StorageManager.getStorageVolume(File)</code> 
     49 <code>StorageVolume</code>  <code>StorageVolume</code> 
     50 <code>createAccessIntent()</code>  
     51 </p>
     52 
     53 <p>
     54  SD  
     55 <code>StorageVolume.createAccessIntent()</code>  null   null 
     56 <code>StorageVolume.createAccessIntent()</code>  null 
     57 
     58 
     59 </p>
     60 
     61 <p> 
     62 <code>Pictures</code> </p>
     63 
     64 <pre>
     65 StorageManager sm = (StorageManager)getSystemService(Context.STORAGE_SERVICE);
     66 StorageVolume volume = sm.getPrimaryVolume();
     67 Intent intent = volume.createAccessIntent(Environment.DIRECTORY_PICTURES);
     68 startActivityForResult(intent, request_code);
     69 </pre>
     70 
     71 <p> UI 
     72 </p>
     73 
     74 <img src="{@docRoot}images/android-7.0/scoped-directory-access-framed.png" srcset="{@docRoot}images/android-7.0/scoped-directory-access-framed.png 1x,
     75 {@docRoot}images/android-7.0/scoped-directory-access-framed_2x.png 2x" />
     76 <p class="img-caption"><strong> 1.</strong> Pictures 
     77 </p>
     78 
     79 <p>
     80 <code>Activity.RESULT_OK</code> URI  
     81 <code>onActivityResult()</code>  URI <a href="{@docRoot}guide/topics/providers/document-provider.html">  </a> URI 
     82 
     83 
     84 
     85 </p>
     86 
     87 <p>
     88 <code>Activity.RESULT_CANCELED</code> null  
     89 <code>onActivityResult()</code> </p>
     90 
     91 <p class="note"><b></b>:
     92 </p>
     93 
     94 <h2 id="removable"> </h2>
     95 
     96 <p>  {@link android.os.Environment#MEDIA_MOUNTED}  {@link android.content.BroadcastReceiver} 
     97 
     98 </p>
     99 
    100 <pre>
    101 &lt;receiver
    102     android:name=".MediaMountedReceiver"
    103     android:enabled="true"
    104     android:exported="true" &gt;
    105     &lt;intent-filter&gt;
    106         &lt;action android:name="android.intent.action.MEDIA_MOUNTED" /&gt;
    107         &lt;data android:scheme="file" /&gt;
    108     &lt;/intent-filter&gt;
    109 &lt;/receiver&gt;
    110 </pre>
    111 
    112 <p> SD  
    113 {@link android.os.Environment#MEDIA_MOUNTED}   <code>StorageVolume</code>  
    114 
    115   <code>Pictures</code> 
    116 </p>
    117 
    118 <pre>
    119 // BroadcastReceiver has already cached the MEDIA_MOUNTED
    120 // notification Intent in mediaMountedIntent
    121 StorageVolume volume = (StorageVolume)
    122     mediaMountedIntent.getParcelableExtra(StorageVolume.EXTRA_STORAGE_VOLUME);
    123 volume.createAccessIntent(Environment.DIRECTORY_PICTURES);
    124 startActivityForResult(intent, request_code);
    125 </pre>
    126 
    127 <h2 id="best"> </h2>
    128 
    129 <p> URI 
    130  URI 
    131 <code>getContentResolver().takePersistableUriPermssion()</code> 
    132  URI  <code>RESULT_OK</code>  UI 
    133 
    134 </p>
    135 
    136 <p>
    137  
    138 UI  [<b>Don't ask again</b>] 
    139 </p>
    140 
    141 <img src="{@docRoot}images/android-7.0/scoped-directory-access-dont-ask.png" srcset="{@docRoot}images/android-7.0/scoped-directory-access-dont-ask.png 1x,
    142 {@docRoot}images/android-7.0/scoped-directory-access-dont-ask_2x.png 2x" />
    143 <p class="img-caption"><strong> 1.</strong>   2 
    144 </p>
    145 
    146 <p> [<b>Don't ask again</b>]  UI 
    147 
    148 </p>