Home | History | Annotate | Download | only in features
      1 page.title=
      2 page.keywords=preview,sdk,scoped directory access
      3 page.tags=androidn
      4 
      5 @jd:body
      6 
      7 <div id="qv-wrapper">
      8 <div id="qv">
      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} ac
     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>  <code>StorageVolume</code> 
     41  <code>StorageVolume.createAccessIntent()</code> 
     42 
     43  ()  <code>StorageManager.getVolumesList()</code>
     44 
     45 </p>
     46 
     47 <p> <code>Pictures</code> 
     48 </p>
     49 
     50 <pre>
     51 StorageManager sm = (StorageManager)getSystemService(Context.STORAGE_SERVICE);
     52 StorageVolume volume = sm.getPrimaryVolume();
     53 Intent intent = volume.createAccessIntent(Environment.DIRECTORY_PICTURES);
     54 startActivityForResult(intent, request_code);
     55 </pre>
     56 
     57 <p> UI 
     58 </p>
     59 
     60 <img src="{@docRoot}preview/images/scoped-folder-access-framed.png" srcset="{@docRoot}preview/images/scoped-folder-access-framed.png 1x,
     61 {@docRoot}preview/images/scoped-folder-access-framed_2x.png 2x" />
     62 <p class="img-caption"><strong> 1.</strong>  [] 
     63 </p>
     64 
     65 <p> <code>onActivityResult()</code>  <code>Activity.RESULT_OK</code>  URI 
     66 
     67  URI <a href="{@docRoot}guide/topics/providers/document-provider.html"></a> URI
     68 
     69 
     70 
     71 </p>
     72 
     73 <p> <code>onActivityResult()</code>  <code>Activity.RESULT_CANCELED</code>  Null 
     74 
     75 </p>
     76 
     77 <p class="note"><b></b>
     78 </p>
     79 
     80 <h2 id="removable"></h2>
     81 
     82 <p> {@link android.os.Environment#MEDIA_MOUNTED}  {@link android.content.BroadcastReceiver}
     83 
     84 </p>
     85 
     86 <pre>
     87 &lt;receiver
     88     android:name=".MediaMountedReceiver"
     89     android:enabled="true"
     90     android:exported="true" &gt;
     91     &lt;intent-filter&gt;
     92         &lt;action android:name="android.intent.action.MEDIA_MOUNTED" /&gt;
     93         &lt;data android:scheme="file" /&gt;
     94     &lt;/intent-filter&gt;
     95 &lt;/receiver&gt;
     96 </pre>
     97 
     98 <p> ( SD )  {@link android.os.Environment#MEDIA_MOUNTED} 
     99  <code>StorageVolume</code> 
    100 
    101  <code>Pictures</code> 
    102 </p>
    103 
    104 <pre>
    105 // BroadcastReceiver has already cached the MEDIA_MOUNTED
    106 // notification Intent in mediaMountedIntent
    107 StorageVolume volume = (StorageVolume)
    108     mediaMountedIntent.getParcelableExtra(StorageVolume.EXTRA_STORAGE_VOLUME);
    109 volume.createAccessIntent(Environment.DIRECTORY_PICTURES);
    110 startActivityForResult(intent, request_code);
    111 </pre>
    112 
    113 <h2 id="best"></h2>
    114 
    115 <p> URI 
    116  URI  <code>getContentResolver().takePersistableUriPermssion()</code>
    117 
    118  URI  <code>RESULT_OK</code> UI
    119 
    120 </p>
    121 
    122 <p>
    123 
    124 </p>
    125