Home | History | Annotate | Download | only in features
      1 page.title=   
      2 page.keywords=preview, sdk,    
      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>    
     19 <code>Pictures</code>        .     
     20       
     21  .    .</p>
     22 
     23 <ul>
     24 <li> {@link android.Manifest.permission#READ_EXTERNAL_STORAGE}
     25  {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} 
     26        .
     27         .</li>
     28 <li>,
     29 <a href="{@docRoot}guide/topics/providers/document-provider.html">
     30  </a>   UI   
     31   .      
     32   .</li>
     33 </ul>
     34 
     35 <p>Android N      
     36   API . </p>
     37 
     38 <h2 id="accessing">   </h2>
     39 
     40 <p><code>StorageManager</code>   
     41 <code>StorageVolume</code>  .  ,  
     42 <code>StorageVolume.createAccessIntent()</code>    .
     43      .    
     44      
     45 <code>StorageManager.getVolumesList()</code> .</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>  
     56 null .   null      
     57 <code>StorageVolume.createAccessIntent()</code> null
     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>      ,
     72    UI    .</p>
     73 
     74 <img src="{@docRoot}preview/images/scoped-folder-access-framed.png" srcset="{@docRoot}preview/images/scoped-folder-access-framed.png 1x,
     75 {@docRoot}preview/images/scoped-folder-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>   
     81 <code>onActivityResult()</code>  URI    . 
     82 URI    .
     83 <a href="{@docRoot}guide/topics/providers/document-provider.html">
     84  </a>
     85  URI   .</p>
     86 
     87 <p>     
     88 <code>Activity.RESULT_CANCELED</code>   
     89 <code>onActivityResult()</code>  null   .</p>
     90 
     91 <p class="note"><b></b>:       
     92         .</p>
     93 
     94 <h2 id="removable">   </h2>
     95 
     96 <p>        
     97   
     98 {@link android.os.Environment#MEDIA_MOUNTED}   {@link android.content.BroadcastReceiver} .</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}  .  
    114           <code>StorageVolume</code> 
    115 . 
    116   <code>Pictures</code>   .</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    
    133 <code>RESULT_OK</code>    UI
    134  .</p>
    135 
    136 <p>    
    137     .   
    138     .      
    139 , UI <b>Don't ask again</b>  .</p>
    140 
    141 <img src="{@docRoot}preview/images/scoped-folder-access-dont-ask.png" srcset="{@docRoot}preview/images/scoped-folder-access-dont-ask.png 1x,
    142 {@docRoot}preview/images/scoped-folder-access-dont-ask_2x.png 2x" />
    143 <p class="img-caption"><strong> 1.</strong>   
    144     .</p>
    145 
    146 <p> <b>Don't ask again</b>         
    147   ,
    148    UI  .</p>