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