Dirk Dougherty | cf65e484 | 2016-03-07 22:31:57 -0800 | [diff] [blame] | 1 | page.title=Android N for Developers |
Dirk Dougherty | 43eb951 | 2016-03-03 14:53:16 -0800 | [diff] [blame] | 2 | meta.tags="preview", "androidn" |
| 3 | page.tags="preview", "developer preview" |
Dirk Dougherty | a6495a92 | 2016-03-04 15:21:59 -0800 | [diff] [blame] | 4 | page.image=images/cards/card-n-apis_2x.png |
Dirk Dougherty | 5748bc4 | 2016-02-06 18:24:32 -0800 | [diff] [blame] | 5 | @jd:body |
| 6 | |
Dirk Dougherty | cf65e484 | 2016-03-07 22:31:57 -0800 | [diff] [blame] | 7 | |
| 8 | |
| 9 | |
| 10 | <div id="qv-wrapper"> |
| 11 | <div id="qv"> |
David Friedman | 82c668f | 2016-05-17 23:53:21 -0700 | [diff] [blame] | 12 | <h2>Key Developer Features</h2> |
Dirk Dougherty | cf65e484 | 2016-03-07 22:31:57 -0800 | [diff] [blame] | 13 | <ol> |
| 14 | <ul style="list-style-type:none;"> |
David Friedman | 82c668f | 2016-05-17 23:53:21 -0700 | [diff] [blame] | 15 | <li><a href="#multi-window_support">Multi-window Support</a></li> |
Dirk Dougherty | cf65e484 | 2016-03-07 22:31:57 -0800 | [diff] [blame] | 16 | <li><a href="#notification_enhancements">Notifications</a></li> |
David Friedman | 82c668f | 2016-05-17 23:53:21 -0700 | [diff] [blame] | 17 | <li><a href="#jit_aot">JIT/AOT Compilation</a></li> |
| 18 | <li><a href="#quick_path_to_app_install">Quick Path to App Install</a></li> |
| 19 | <li><a href="#doze_on_the_go">Doze on the Go</a></li> |
| 20 | <li><a href="#background_optimizations">Background Optimizations</a></li> |
Dirk Dougherty | 5942892 | 2016-03-10 18:54:49 -0800 | [diff] [blame] | 21 | <li><a href="#data_saver">Data Saver</a></li> |
Andrew Solovay | 097b115 | 2016-04-06 17:33:00 -0700 | [diff] [blame] | 22 | <li><a href="#vulkan">Vulkan API</a></li> |
Dirk Dougherty | 5942892 | 2016-03-10 18:54:49 -0800 | [diff] [blame] | 23 | <li><a href="#tile_api">Quick Settings Tile API</a></li> |
David Friedman | 82c668f | 2016-05-17 23:53:21 -0700 | [diff] [blame] | 24 | <li><a href="#number-blocking">Number Blocking</a></li> |
| 25 | <li><a href="#call_screening">Call Screening</a></li> |
| 26 | <li><a href="#multi-locale_languages">Locales and Languages</a></li> |
Eric Schmidt | 700127a | 2016-05-12 16:29:18 -0700 | [diff] [blame] | 27 | <li><a href="#emoji">New Emojis</a></li> |
Dirk Dougherty | 5942892 | 2016-03-10 18:54:49 -0800 | [diff] [blame] | 28 | <li><a href="#icu4">ICU4J APIs in Android</a></li> |
| 29 | <li><a href="#gles_32">OpenGL ES 3.2 API</a></li> |
David Friedman | 82c668f | 2016-05-17 23:53:21 -0700 | [diff] [blame] | 30 | <li><a href="#android_tv_recording">Android TV Recording</a></li> |
Dirk Dougherty | 5942892 | 2016-03-10 18:54:49 -0800 | [diff] [blame] | 31 | <li><a href="#android_for_work">Android for Work</a></li> |
| 32 | <li><a href="#accessibility_enhancements">Accessibility</a></li> |
| 33 | <li><a href="#direct_boot">Direct Boot</a></li> |
| 34 | <li><a href="#key_attestation">Key Attestation</a></li> |
| 35 | <li><a href="#network_security_config">Network Security Config</a></li> |
| 36 | <li><a href="#default_trusted_ca">Default Trusted CA</a></li> |
David Friedman | 82c668f | 2016-05-17 23:53:21 -0700 | [diff] [blame] | 37 | <li><a href="#apk_signature_v2">APK Signature Scheme v2</a></li> |
| 38 | <li><a href="#scoped_directory_access">Scoped Directory Access</a></li> |
David Friedman | 93970ba | 2016-05-13 01:23:13 -0700 | [diff] [blame] | 39 | <li><a href="#keyboard_shortcuts_helper">Keyboard Shortcuts Helper</a></li> |
Hemal Patel | 37663db | 2016-06-13 14:37:36 -0700 | [diff] [blame^] | 40 | <li><a href="#custom_pointer_api">Custom Pointer API</a></li> |
David Friedman | 93970ba | 2016-05-13 01:23:13 -0700 | [diff] [blame] | 41 | <li><a href="#sustained_performance_api">Sustained Performance API</a></li> |
David Friedman | 182e8b5 | 2016-05-13 10:03:52 -0700 | [diff] [blame] | 42 | <li><a href="#vr">VR Support</a></li> |
David Friedman | 82c668f | 2016-05-17 23:53:21 -0700 | [diff] [blame] | 43 | <li><a href="#print_svc">Print Service Enhancements</a></li> |
Eric Schmidt | 186fada | 2016-04-27 11:48:22 -0700 | [diff] [blame] | 44 | <li><a href="#virtual_files">Virtual Files</a></li> |
David Friedman | 93970ba | 2016-05-13 01:23:13 -0700 | [diff] [blame] | 45 | <li><a href="#framemetrics_api">FrameMetricsListener API</a></li> |
Dirk Dougherty | cf65e484 | 2016-03-07 22:31:57 -0800 | [diff] [blame] | 46 | </ol> |
| 47 | </div> |
| 48 | </div> |
| 49 | |
| 50 | |
| 51 | |
| 52 | <p>Android N is still in active development, but you can try it |
| 53 | now as part of the N Developer Preview. The sections below highlight some of |
| 54 | the new features for developers. </p> |
| 55 | |
Andrew Solovay | 9b21857 | 2016-03-09 11:17:07 -0800 | [diff] [blame] | 56 | <p> |
| 57 | Make sure to check out the <a href= |
| 58 | "{@docRoot}preview/behavior-changes.html">Behavior Changes</a> to learn about |
| 59 | areas where platform changes may affect your apps, take a look at the |
| 60 | developer guides to learn more about key features, and download the <a href= |
| 61 | "{@docRoot}preview/setup-sdk.html#docs-dl">API Reference</a> for details on |
| 62 | new APIs. |
| 63 | </p> |
Dirk Dougherty | cf65e484 | 2016-03-07 22:31:57 -0800 | [diff] [blame] | 64 | |
David Friedman | 82c668f | 2016-05-17 23:53:21 -0700 | [diff] [blame] | 65 | <h2 id="multi-window_support">Multi-window Support</h2> |
Dirk Dougherty | cf65e484 | 2016-03-07 22:31:57 -0800 | [diff] [blame] | 66 | |
| 67 | |
| 68 | <p>In Android N, we're introducing a new and much-requested multitasking feature |
| 69 | into the platform — multi-window support. </p> |
| 70 | |
| 71 | <p>Users can now pop open two apps on the screen at once. </p> |
| 72 | <ul> |
| 73 | <li>On phones and tablets |
| 74 | running Android N, users can run two apps side-by-side or |
| 75 | one-above-the-other in splitscreen mode. Users can resize the apps by dragging |
| 76 | the divider between them. </li> |
| 77 | |
Andrew Solovay | 9b21857 | 2016-03-09 11:17:07 -0800 | [diff] [blame] | 78 | <li>On Android TV devices, apps can put themselves in <a |
| 79 | href="{@docRoot}preview/features/picture-in-picture.html">picture-in-picture |
| 80 | mode</a>, allowing them to continue showing content while the user browses or |
Daniel Yu | 0ab19aa | 2016-03-14 15:35:38 -0700 | [diff] [blame] | 81 | interacts with other apps.</li> |
Dirk Dougherty | cf65e484 | 2016-03-07 22:31:57 -0800 | [diff] [blame] | 82 | </ul> |
| 83 | |
Dirk Dougherty | cf65e484 | 2016-03-07 22:31:57 -0800 | [diff] [blame] | 84 | <div class="col-4of10"> |
Dirk Dougherty | 5942892 | 2016-03-10 18:54:49 -0800 | [diff] [blame] | 85 | <img src="{@docRoot}preview/images/mw-portrait.png" alt="" style="height:460px;padding-left:1em;" |
Dirk Dougherty | cf65e484 | 2016-03-07 22:31:57 -0800 | [diff] [blame] | 86 | id="img-split-screen" /> |
| 87 | <p class="img-caption"> |
Dirk Dougherty | 5942892 | 2016-03-10 18:54:49 -0800 | [diff] [blame] | 88 | <strong>Figure 1.</strong> Apps running in split-screen mode. |
Dirk Dougherty | 5748bc4 | 2016-02-06 18:24:32 -0800 | [diff] [blame] | 89 | </p> |
David Friedman | 182e8b5 | 2016-05-13 10:03:52 -0700 | [diff] [blame] | 90 | |
Dirk Dougherty | cf65e484 | 2016-03-07 22:31:57 -0800 | [diff] [blame] | 91 | </div> |
| 92 | |
Dirk Dougherty | cf65e484 | 2016-03-07 22:31:57 -0800 | [diff] [blame] | 93 | <p>Especially on tablets and other larger-screen devices, multi-window support |
| 94 | gives you new ways to engage users. You can even enable drag-and-drop in |
| 95 | your app to let users conveniently drag content to or from your app — a great |
| 96 | way to enhance your user experience. </p> |
| 97 | |
| 98 | <p>It's straightforward to add multi-window support to your app and configure how it |
| 99 | handles multi-window display. For example, you can specify your activity's |
| 100 | minimum allowable dimensions, preventing users from resizing the activity below |
| 101 | that size. You can also disable multi-window display for your app, which |
| 102 | ensures that the system will only show your app in full-screen mode.</p> |
| 103 | |
Andrew Solovay | 9b21857 | 2016-03-09 11:17:07 -0800 | [diff] [blame] | 104 | <p> |
| 105 | For more information, see the <a href= |
| 106 | "{@docRoot}preview/features/multi-window.html">Multi-Window Support</a> |
| 107 | developer documentation. |
| 108 | </p> |
Dirk Dougherty | cf65e484 | 2016-03-07 22:31:57 -0800 | [diff] [blame] | 109 | |
David Friedman | 82c668f | 2016-05-17 23:53:21 -0700 | [diff] [blame] | 110 | <h2 id="notification_enhancements">Notification Enhancements</h2> |
Dirk Dougherty | cf65e484 | 2016-03-07 22:31:57 -0800 | [diff] [blame] | 111 | |
| 112 | <p>In Android N we've redesigned notifications to make them easier and faster to |
| 113 | use. Some of the changes include:</p> |
| 114 | |
| 115 | <ul> |
Andrew Solovay | 9b21857 | 2016-03-09 11:17:07 -0800 | [diff] [blame] | 116 | <li> |
| 117 | <strong>Template updates</strong>: We're updating notification templates to |
| 118 | put a new emphasis on hero image and avatar. Developers will be able to |
| 119 | take advantage of the new templates with minimal adjustments in their code. |
| 120 | </li> |
| 121 | |
| 122 | <li> |
Eric Schmidt | 8044822 | 2016-05-31 11:56:03 -0700 | [diff] [blame] | 123 | <strong>Messaging style customization</strong>: You can customize more of |
| 124 | the user interface labels associated with your notifications using the |
| 125 | <code>MessagingStyle</code> class. You can configure the message, |
| 126 | conversation title, and content view. |
Eric Schmidt | 57a83b5 | 2016-05-10 12:37:38 -0700 | [diff] [blame] | 127 | </li> |
| 128 | |
| 129 | <li> |
Andrew Solovay | 9b21857 | 2016-03-09 11:17:07 -0800 | [diff] [blame] | 130 | <strong>Bundled notifications</strong>: The system can group messages |
| 131 | together, for example by message topic, and display the group. A user can |
| 132 | take actions, such as Dismiss or Archive, on them in place. If you’ve |
| 133 | implemented notifications for Android Wear, you’ll already be familiar with |
Andrew Solovay | 069ac63 | 2016-03-11 11:23:27 -0800 | [diff] [blame] | 134 | this model. |
Andrew Solovay | 9b21857 | 2016-03-09 11:17:07 -0800 | [diff] [blame] | 135 | </li> |
| 136 | |
| 137 | <li> |
| 138 | <strong>Direct reply</strong>: For real-time communication apps, the |
| 139 | Android system supports inline replies so that users can quickly respond to |
| 140 | an SMS or text message directly within the notification interface. |
| 141 | </li> |
| 142 | |
| 143 | <li> |
| 144 | <strong>Custom views</strong>: Two new APIs enable you to leverage system |
| 145 | decorations, such as notification headers and actions, when using custom |
| 146 | views in notifications. |
| 147 | </li> |
Dirk Dougherty | cf65e484 | 2016-03-07 22:31:57 -0800 | [diff] [blame] | 148 | </ul> |
| 149 | |
| 150 | <div class="col-4of12"> |
Andrew Solovay | 9b21857 | 2016-03-09 11:17:07 -0800 | [diff] [blame] | 151 | <img src="{@docRoot}preview/images/notifications-1.png" alt="" |
| 152 | style="padding:.5em;max-width:226px"> |
Dirk Dougherty | cf65e484 | 2016-03-07 22:31:57 -0800 | [diff] [blame] | 153 | </div> |
Andrew Solovay | 9b21857 | 2016-03-09 11:17:07 -0800 | [diff] [blame] | 154 | |
Dirk Dougherty | cf65e484 | 2016-03-07 22:31:57 -0800 | [diff] [blame] | 155 | <div class="col-4of12"> |
Andrew Solovay | 9b21857 | 2016-03-09 11:17:07 -0800 | [diff] [blame] | 156 | <img src="{@docRoot}preview/images/notifications-3.png" alt="" |
| 157 | style="padding:.5em;max-width:226px"> |
Dirk Dougherty | cf65e484 | 2016-03-07 22:31:57 -0800 | [diff] [blame] | 158 | </div> |
Andrew Solovay | 9b21857 | 2016-03-09 11:17:07 -0800 | [diff] [blame] | 159 | |
Dirk Dougherty | cf65e484 | 2016-03-07 22:31:57 -0800 | [diff] [blame] | 160 | <div class="col-4of12"> |
Andrew Solovay | 9b21857 | 2016-03-09 11:17:07 -0800 | [diff] [blame] | 161 | <img src="{@docRoot}preview/images/notifications-2.png" alt="" |
| 162 | style="padding:.5em;max-width:226px"> |
Dirk Dougherty | cf65e484 | 2016-03-07 22:31:57 -0800 | [diff] [blame] | 163 | </div> |
| 164 | |
| 165 | |
| 166 | <p class="img-caption"> |
Adarsh Fernando | 3760156 | 2016-03-09 09:53:57 -0800 | [diff] [blame] | 167 | <strong>Figure 2.</strong> Bundled notifications and direct reply. |
Dirk Dougherty | cf65e484 | 2016-03-07 22:31:57 -0800 | [diff] [blame] | 168 | </p> |
| 169 | |
Andrew Solovay | 9b21857 | 2016-03-09 11:17:07 -0800 | [diff] [blame] | 170 | <p>To learn how to implement the new features, see the |
| 171 | <a href="{@docRoot}preview/features/notification-updates.html">Notifications</a> |
| 172 | guide.</p> |
Dirk Dougherty | cf65e484 | 2016-03-07 22:31:57 -0800 | [diff] [blame] | 173 | |
| 174 | |
Dirk Dougherty | cf65e484 | 2016-03-07 22:31:57 -0800 | [diff] [blame] | 175 | |
David Friedman | 82c668f | 2016-05-17 23:53:21 -0700 | [diff] [blame] | 176 | <h2 id="jit_aot">Profile-guided JIT/AOT Compilation</h2> |
Dirk Dougherty | cf65e484 | 2016-03-07 22:31:57 -0800 | [diff] [blame] | 177 | |
| 178 | <p>In Android N, we've added a Just in Time (JIT) compiler with code profiling to |
| 179 | ART, which lets it constantly improve the performance of Android apps as they |
| 180 | run. The JIT compiler complements ART's current Ahead of Time (AOT) compiler |
| 181 | and helps improve runtime performance, save storage space, and speed up app |
| 182 | updates and system updates.</p> |
| 183 | |
| 184 | <p>Profile-guided compilation lets ART manage the AOT/JIT compilation for each app |
| 185 | according to its actual usage, as well as conditions on the device. For |
| 186 | example, ART maintains a profile of each app's hot methods and can precompile |
| 187 | and cache those methods for best performance. It leaves other parts of the app |
| 188 | uncompiled until they are actually used.</p> |
| 189 | |
| 190 | <p>Besides improving performance for key parts of the app, profile-guided |
| 191 | compilation helps reduce an app's overall RAM footprint, including associated |
| 192 | binaries. This feature is especially important on low-memory devices.</p> |
| 193 | |
| 194 | <p>ART manages profile-guided compilation in a way that minimizes impact on the |
| 195 | device battery. It does precompilation only when then the device is idle and |
| 196 | charging, saving time and battery by doing that work in advance.</p> |
| 197 | |
David Friedman | 82c668f | 2016-05-17 23:53:21 -0700 | [diff] [blame] | 198 | <h2 id="quick_path_to_app_install">Quick Path to App Install</h2> |
Dirk Dougherty | cf65e484 | 2016-03-07 22:31:57 -0800 | [diff] [blame] | 199 | |
| 200 | <p>One of the most tangible benefits of ART's JIT compiler is the speed of app |
| 201 | installs and system updates. Even large apps that required several minutes to |
| 202 | optimize and install in Android 6.0 can now install in just a matter of |
| 203 | seconds. System updates are also faster, since there's no more optimizing step. </p> |
| 204 | |
David Friedman | 82c668f | 2016-05-17 23:53:21 -0700 | [diff] [blame] | 205 | <h2 id="doze_on_the_go">Doze on the Go...</h2> |
Dirk Dougherty | cf65e484 | 2016-03-07 22:31:57 -0800 | [diff] [blame] | 206 | |
| 207 | <p>Android 6.0 introduced Doze, a system mode that saves battery by deferring |
| 208 | apps' CPU and network activities when the device is idle, such as when it's |
| 209 | sitting on a table or in a drawer. </p> |
| 210 | |
| 211 | <p>Now in Android N, Doze takes a step further and saves battery while on the go. |
| 212 | Any time the screen is off for a period of time and the device is unplugged, |
| 213 | Doze applies a subset of the familiar CPU and network restrictions to apps. |
| 214 | This means users can save battery even when carrying their devices in their |
| 215 | pockets.</p> |
| 216 | |
| 217 | |
Dirk Dougherty | 5942892 | 2016-03-10 18:54:49 -0800 | [diff] [blame] | 218 | <img src="/preview/images/doze-diagram-1.png" |
| 219 | alt="" id="figure1" /> |
| 220 | <p class="img-caption"> |
Andrew Solovay | 069ac63 | 2016-03-11 11:23:27 -0800 | [diff] [blame] | 221 | <strong>Figure 3.</strong> Doze now applies |
Dirk Dougherty | 5942892 | 2016-03-10 18:54:49 -0800 | [diff] [blame] | 222 | restrictions to improve battery life even when the device is not stationary. |
| 223 | </p> |
Dirk Dougherty | cf65e484 | 2016-03-07 22:31:57 -0800 | [diff] [blame] | 224 | |
| 225 | |
| 226 | <p>A short time after the screen turns off while the device is on battery, Doze |
| 227 | restricts network access and defers jobs and syncs. During brief maintenance |
| 228 | windows, applications are allowed network access and any of their deferred |
| 229 | jobs/syncs are executed. Turning the screen on or plugging in the device brings |
| 230 | the device out of Doze.</p> |
| 231 | |
| 232 | <p>When the device is stationary again, with screen off and on battery for a |
| 233 | period of time, Doze applies the full CPU and network restrictions on {@link |
| 234 | android.os.PowerManager.WakeLock}, {@link android.app.AlarmManager} alarms, and |
| 235 | GPS/Wi-Fi scans.</p> |
| 236 | |
| 237 | <p>The best practices for adapting your app to Doze are the same whether the |
| 238 | device is moving or not, so if you already updated your app to gracefully |
| 239 | handle Doze, you're all set. If not, start <a |
Andrew Solovay | 9b21857 | 2016-03-09 11:17:07 -0800 | [diff] [blame] | 240 | href="{@docRoot}training/monitoring-device-state/doze-standby.html#assessing_your_app">adapting |
Dirk Dougherty | cf65e484 | 2016-03-07 22:31:57 -0800 | [diff] [blame] | 241 | your app to Doze</a> now.</p> |
| 242 | |
David Friedman | 82c668f | 2016-05-17 23:53:21 -0700 | [diff] [blame] | 243 | <h2 id="background_optimizations">Project Svelte: Background Optimizations</h2> |
Dirk Dougherty | cf65e484 | 2016-03-07 22:31:57 -0800 | [diff] [blame] | 244 | |
| 245 | <p>Project Svelte is an ongoing effort to minimize RAM use by system and apps |
| 246 | across the range of Android devices in the ecosystem. In Android N, Project |
| 247 | Svelte is focused on optimizing the way apps run in the background. </p> |
| 248 | |
| 249 | <p>Background processing is an essential part of most apps. When handled right, it |
| 250 | can make your user experience amazing — immediate, fast, and context-aware. |
| 251 | When not handled right, background processing can needlessly consume RAM (and |
| 252 | battery) and affect system performance for other apps. </p> |
| 253 | |
Andrew Solovay | d6a6f96 | 2016-03-10 15:01:29 -0800 | [diff] [blame] | 254 | <p>Since Android 5.0, {@link android.app.job.JobScheduler} has been the |
| 255 | preferred way of performing background work in a way that's good |
Dirk Dougherty | cf65e484 | 2016-03-07 22:31:57 -0800 | [diff] [blame] | 256 | for users. Apps can schedule jobs while letting the system optimize based on |
| 257 | memory, power, and connectivity conditions. JobScheduler offers control and |
| 258 | simplicity, and we want all apps to use it. </p> |
| 259 | |
Andrew Solovay | 9b21857 | 2016-03-09 11:17:07 -0800 | [diff] [blame] | 260 | <p> |
| 261 | Another good option is <a href= |
| 262 | "https://developers.google.com/android/reference/com/google/android/gms/gcm/GcmNetworkManager"> |
| 263 | <code>GCMNetworkManager</code></a>, part of Google Play Services, which |
| 264 | offers similar job scheduling with compatibility across legacy versions of |
| 265 | Android. |
| 266 | </p> |
Dirk Dougherty | cf65e484 | 2016-03-07 22:31:57 -0800 | [diff] [blame] | 267 | |
Andrew Solovay | d6a6f96 | 2016-03-10 15:01:29 -0800 | [diff] [blame] | 268 | <p>We're continuing to extend <code>JobScheduler</code> and |
| 269 | <code>GCMNetworkManager</code> to meet more of |
Dirk Dougherty | cf65e484 | 2016-03-07 22:31:57 -0800 | [diff] [blame] | 270 | your use cases — for example, in Android N you can now schedule background |
| 271 | work based on changes in Content Providers. At the same time we're starting to |
| 272 | deprecate some of the older patterns that can reduce system performance, |
| 273 | especially on low-memory devices.</p> |
| 274 | |
| 275 | <p>In Android N we're removing three commonly-used implicit broadcasts — |
Adarsh Fernando | 3760156 | 2016-03-09 09:53:57 -0800 | [diff] [blame] | 276 | {@link android.net.ConnectivityManager#CONNECTIVITY_ACTION}, {@link |
| 277 | android.hardware.Camera#ACTION_NEW_PICTURE}, and {@link |
| 278 | android.hardware.Camera#ACTION_NEW_VIDEO} — since those can wake the |
Dirk Dougherty | cf65e484 | 2016-03-07 22:31:57 -0800 | [diff] [blame] | 279 | background processes of multiple apps at once and strain memory and battery. If |
| 280 | your app is receiving these, take advantage of the N Developer Preview to |
| 281 | migrate to <code>JobScheduler</code> and related APIs instead. </p> |
| 282 | |
Andrew Solovay | 9b21857 | 2016-03-09 11:17:07 -0800 | [diff] [blame] | 283 | <p> |
| 284 | Take a look at the <a href= |
| 285 | "{@docRoot}preview/features/background-optimization.html">Background |
| 286 | Optimizations</a> documentation for details. |
| 287 | </p> |
Dirk Dougherty | cf65e484 | 2016-03-07 22:31:57 -0800 | [diff] [blame] | 288 | |
Dirk Dougherty | 5942892 | 2016-03-10 18:54:49 -0800 | [diff] [blame] | 289 | |
| 290 | <h2 id="data_saver">Data Saver</h2> |
| 291 | |
| 292 | <div class="col-5of12" style="margin-right:1.5em;"> |
| 293 | <img src="{@docRoot}preview/images/datasaver.png" style="border:2px solid #ddd"> |
| 294 | |
| 295 | <p class="img-caption" style="padding-right:2em;"> |
| 296 | <strong>Figure 4.</strong> Data Saver in Settings. |
| 297 | </p> |
| 298 | </div> |
| 299 | |
| 300 | <p>Over the life of a mobile device, the cost of a cellular data plan typically |
| 301 | exceeds the cost of the device itself. For many users, cellular data is an |
| 302 | expensive resource that they want to conserve. </p> |
| 303 | |
| 304 | <p>Android N introduces Data Saver mode, a new system service that helps reduce |
| 305 | cellular data use by apps, whether roaming, near the end of the billing cycle, |
| 306 | or on a small prepaid data pack. Data Saver gives users control over how apps |
| 307 | use cellular data and lets developers provide more efficient service when Data |
| 308 | Saver is on. </p> |
| 309 | |
| 310 | <p>When a user enables Data Saver in <strong>Settings</strong> and the device is |
| 311 | on a metered network, the system blocks background data usage and signals apps |
| 312 | to use less data in the foreground wherever possible — such as by limiting |
| 313 | bit rate for streaming, reducing image quality, deferring optimistic precaching, |
| 314 | and so on. Users can whitelist specific apps to allow background metered data |
| 315 | usage even when Data Saver is turned on.</p> |
| 316 | |
| 317 | <p>Android N extends the {@link android.net.ConnectivityManager} to provide apps a |
| 318 | way to <a href="{@docRoot}preview/features/data-saver.html#status">retrieve the |
| 319 | user's Data Saver preferences</a> and <a |
| 320 | href="{@docRoot}preview/features/data-saver.html#monitor-changes">monitor |
| 321 | preference changes</a>. All apps should check whether the user has enabled Data |
| 322 | Saver and make an effort to limit foreground and background data usage.</p> |
| 323 | |
| 324 | |
Andrew Solovay | 097b115 | 2016-04-06 17:33:00 -0700 | [diff] [blame] | 325 | <h2 id="vulkan">Vulkan API</h2> |
| 326 | |
| 327 | <p> |
| 328 | Android N integrates <a href="http://www.khronos.org/vulkan" class= |
| 329 | "external-link">Vulkan™</a>, a new 3D rendering API, into the platform. Like |
| 330 | <a href="https://www.khronos.org/opengles/" class="external-link">OpenGL™ |
| 331 | ES</a>, Vulkan is an open standard for 3D graphics and rendering maintained |
| 332 | by the Khronos Group. |
| 333 | </p> |
| 334 | |
| 335 | <p> |
| 336 | Vulkan is designed from the ground up to minimize CPU overhead in the driver, |
| 337 | and allow your application to control GPU operation more directly. Vulkan |
| 338 | also enables better parallelization by allowing multiple threads to perform |
| 339 | work such as command buffer construction at once. |
| 340 | </p> |
| 341 | |
| 342 | <p> |
| 343 | Vulkan development tools and libraries are rolled into the Android NDK. They |
| 344 | include: |
| 345 | </p> |
| 346 | |
| 347 | <ul> |
| 348 | <li>Headers |
| 349 | </li> |
| 350 | |
| 351 | <li>Validation layers (debug libraries) |
| 352 | </li> |
| 353 | |
| 354 | <li>SPIR-V shader compiler |
| 355 | </li> |
| 356 | |
| 357 | <li>SPIR-V runtime shader compilation library |
| 358 | </li> |
| 359 | </ul> |
| 360 | |
| 361 | <p> |
| 362 | Vulkan is only available to apps on devices with Vulkan-capable hardware, |
David Friedman | 93970ba | 2016-05-13 01:23:13 -0700 | [diff] [blame] | 363 | such as Nexus 5X, Nexus 6P, and Nexus Player. We're working closely with our |
Andrew Solovay | 097b115 | 2016-04-06 17:33:00 -0700 | [diff] [blame] | 364 | partners to bring Vulkan to more devices as soon as possible. |
| 365 | </p> |
| 366 | |
| 367 | <p> |
Andrew Solovay | f5266e5 | 2016-04-12 17:32:57 -0700 | [diff] [blame] | 368 | For more information, see the the <a href= |
| 369 | "{@docRoot}ndk/guides/graphics/index.html">API documentation</a>. |
Andrew Solovay | 097b115 | 2016-04-06 17:33:00 -0700 | [diff] [blame] | 370 | </p> |
| 371 | |
Dirk Dougherty | 5942892 | 2016-03-10 18:54:49 -0800 | [diff] [blame] | 372 | <h2 id="tile_api">Quick Settings Tile API</h2> |
| 373 | |
| 374 | |
| 375 | <div style="float:right;max-width:320px"> |
| 376 | <img src="{@docRoot}preview/images/quicksettings.png" style="padding-left:1.5em;"> |
| 377 | |
| 378 | <p class="img-caption" style="padding-left:2em;"> |
| 379 | <strong>Figure 5.</strong> Quick Settings tiles in the notification shade. |
| 380 | </p> |
| 381 | |
| 382 | |
| 383 | </div><p>Quick Settings is a popular and simple way to expose key settings and actions, |
| 384 | directly from the notification shade. In Android N, we've expanded the scope of |
| 385 | Quick Settings to make it even more useful and convenient. </p> |
| 386 | |
| 387 | <p>We've added more room for additional Quick Settings tiles, which users can |
| 388 | access across a paginated display area by swiping left or right. We've also |
| 389 | given users control over what Quick Settings tiles appear and where they are |
| 390 | displayed — users can add or move tiles just by dragging and dropping them. </p> |
| 391 | |
| 392 | <p>For developers, Android N also adds a new API that lets you define your own |
| 393 | Quick Settings tiles to give users easy access to key controls and actions in your app.</p> |
| 394 | |
| 395 | <p> |
| 396 | Quick Settings tiles are reserved for controls or actions that are either |
| 397 | urgently required or frequently used, and should not be used as shortcuts to |
| 398 | launching an app. |
| 399 | </p> |
| 400 | |
| 401 | <p> |
| 402 | Once you’ve defined your tiles, you can surface them to users, who can add |
| 403 | them to Quick Settings just by drag and drop. |
| 404 | </p> |
| 405 | |
| 406 | <p> |
David Friedman | 182e8b5 | 2016-05-13 10:03:52 -0700 | [diff] [blame] | 407 | For information about creating an app tile, see the documentation for |
Dirk Dougherty | 5942892 | 2016-03-10 18:54:49 -0800 | [diff] [blame] | 408 | <code>android.service.quicksettings.Tile</code> in the downloadable <a href= |
| 409 | "{@docRoot}preview/setup-sdk.html#docs-dl">API Reference</a>. |
| 410 | </p> |
| 411 | |
| 412 | |
| 413 | |
David Friedman | 82c668f | 2016-05-17 23:53:21 -0700 | [diff] [blame] | 414 | <h2 id="number-blocking">Number Blocking</h2> |
Dirk Dougherty | 5942892 | 2016-03-10 18:54:49 -0800 | [diff] [blame] | 415 | |
David Friedman | 82c668f | 2016-05-17 23:53:21 -0700 | [diff] [blame] | 416 | <p>Android N now supports number blocking in the platform and provides a |
Dirk Dougherty | 5942892 | 2016-03-10 18:54:49 -0800 | [diff] [blame] | 417 | framework API to let service providers maintain a blocked-number list. The |
Andrew Solovay | ef93504 | 2016-03-14 14:25:36 -0700 | [diff] [blame] | 418 | default SMS app, the default phone app, and carrier apps can read from and |
Dirk Dougherty | 5942892 | 2016-03-10 18:54:49 -0800 | [diff] [blame] | 419 | write to the blocked-number list. The list is not accessible to other apps.</p> |
| 420 | |
David Friedman | 82c668f | 2016-05-17 23:53:21 -0700 | [diff] [blame] | 421 | <p>By making number blocking a standard feature of the platform, Android provides |
| 422 | a consistent way for apps to support number blocking across a wide range of |
Dirk Dougherty | 5942892 | 2016-03-10 18:54:49 -0800 | [diff] [blame] | 423 | devices. Among the other benefits that apps can take advantage of are:</p> |
| 424 | |
| 425 | <ul> |
| 426 | <li> Numbers blocked on calls are also blocked on texts |
| 427 | <li> Blocked numbers can persist across resets and devices through the Backup & |
| 428 | Restore feature |
| 429 | <li> Multiple apps can use the same blocked numbers list |
| 430 | </ul> |
| 431 | |
| 432 | <p>Additionally, carrier app integration through Android means that carriers can |
| 433 | read the blocked numbers list on the device and perform service-side blocking |
| 434 | for the user in order to stop unwanted calls and texts from reaching the user |
| 435 | through any medium, such as a VOIP endpoint or forwarding phones.</p> |
| 436 | |
| 437 | <p> |
| 438 | For more information, see <code>android.provider.BlockedNumberContract</code> |
| 439 | in the downloadable <a href="{@docRoot}preview/setup-sdk.html#docs-dl">API |
| 440 | Reference</a>. |
| 441 | </p> |
| 442 | |
David Friedman | 82c668f | 2016-05-17 23:53:21 -0700 | [diff] [blame] | 443 | <h2 id="call_screening">Call Screening</h2> |
Dirk Dougherty | 5942892 | 2016-03-10 18:54:49 -0800 | [diff] [blame] | 444 | |
| 445 | <p> |
| 446 | Android N allows the default phone app to screen incoming calls. The phone |
| 447 | app does this by implementing the new <code>CallScreeningService</code>, |
| 448 | which allows the phone app to perform a number of actions based on an |
| 449 | incoming call's {@link android.telecom.Call.Details Call.Details}, such as: |
| 450 | </p> |
| 451 | |
| 452 | <ul> |
| 453 | <li> Reject the incoming call |
| 454 | <li> Do not allow the call to the call log |
| 455 | <li> Do not show the user a notification for the call |
| 456 | </ul> |
| 457 | |
| 458 | <p> |
| 459 | For more information, see <code>android.telecom.CallScreeningService</code> |
| 460 | in the downloadable <a href="{@docRoot}preview/setup-sdk.html#docs-dl">API |
| 461 | Reference</a>. |
| 462 | </p> |
| 463 | |
| 464 | |
David Friedman | 82c668f | 2016-05-17 23:53:21 -0700 | [diff] [blame] | 465 | <h2 id="multi-locale_languages">Multi-locale Support, More Languages</h2> |
Dirk Dougherty | 5942892 | 2016-03-10 18:54:49 -0800 | [diff] [blame] | 466 | |
| 467 | |
| 468 | <p>Android N now lets users select <strong>multiple locales</strong> in Settings, |
| 469 | to better support bilingual use-cases. Apps can use |
| 470 | a new API to get the user's selected locales and then offer more sophisticated |
| 471 | user experiences for multi-locale users — such as showing search results in |
| 472 | multiple languages and not offering to translate webpages in a language the |
| 473 | user already knows.</p> |
| 474 | |
| 475 | <p>Along with multi-locale support, Android N also expands the range of languages |
| 476 | available to users. It offers more than 25 variants each for commonly used |
| 477 | languages such as English, Spanish, French, and Arabic. It also adds partial |
| 478 | support for more than 100 new languages.</p> |
| 479 | |
David Friedman | 182e8b5 | 2016-05-13 10:03:52 -0700 | [diff] [blame] | 480 | <p>Apps can get the list of locales set by the user by calling |
| 481 | <code>LocaleList.GetDefault()</code>. To support the expanded number of locales, Android N is |
| 482 | changing the way that it resolves resources. Make sure that you test and verify that your apps |
Dirk Dougherty | 5942892 | 2016-03-10 18:54:49 -0800 | [diff] [blame] | 483 | working as expected with the new resource resolution logic.</p> |
| 484 | |
| 485 | <p>To learn about the new resource-resolution behavior and the best practices you |
| 486 | should follow, see <a href="{@docRoot}preview/features/multilingual-support.html" |
| 487 | >Multilingual Support</a>.</p> |
| 488 | |
Eric Schmidt | 700127a | 2016-05-12 16:29:18 -0700 | [diff] [blame] | 489 | |
| 490 | <h2 id="emoji">New Emojis</h2> |
| 491 | |
| 492 | <p> |
| 493 | Android N introduces additional emojis and emoji-related features including |
| 494 | skin tone emojis and support for variation |
| 495 | selectors. If your app supports emojis, |
| 496 | follow the guidelines below to take advantage of these emoji-related features. |
| 497 | </p> |
| 498 | |
| 499 | <ul> |
| 500 | <li> |
| 501 | <strong>Check that a device contains an emoji before inserting it.</strong> |
| 502 | To check which emojis are present in the |
| 503 | system font, use the {@link android.graphics.Paint#hasGlyph(String)} method. |
| 504 | </li> |
| 505 | <li> |
| 506 | <strong>Check that an emoji supports variation selectors.</strong> |
| 507 | Variation selectors allow you to |
| 508 | present certain emojis in color or in black-and-white. |
| 509 | On mobile devices, apps should represent emojis in color rather than black-and-white. However, |
| 510 | if your app displays emojis inline with text, then it should use the black-and-white variation. |
| 511 | To determine whether an emoji has a variation, use the variation selector. |
| 512 | For a complete list of characters with variations, review the |
| 513 | <em>emoji variation sequences</em> section of the |
| 514 | <a class="external-link" |
| 515 | href="http://www.unicode.org/Public/9.0.0/ucd/StandardizedVariants-9.0.0d1.txt"> |
| 516 | Unicode documentation on variations</a>. |
| 517 | </li> |
| 518 | <li> |
| 519 | <strong>Check that an emoji supports skin tone.</strong> Android N allows users to modify the |
| 520 | rendered skin tone of emojis to their preference. Keyboard apps should provide visual |
| 521 | indications for emojis that have multiple skin tones and should allow users to |
| 522 | select the skin tone that they prefer. To determine which system emojis have |
| 523 | skin tone modifiers, use the {@link android.graphics.Paint#hasGlyph(String)} |
| 524 | method. You can determine which emojis use skin tones by reading the |
| 525 | <a class="external-link" |
| 526 | href="http://unicode.org/emoji/charts/full-emoji-list.html"> |
| 527 | Unicode documentation</a>. |
| 528 | </li> |
| 529 | </ul> |
| 530 | |
| 531 | |
Dirk Dougherty | 5942892 | 2016-03-10 18:54:49 -0800 | [diff] [blame] | 532 | <h2 id="icu4">ICU4J APIs in Android</h2> |
| 533 | |
| 534 | <p> |
| 535 | Android N now offers a subset of <a href= |
| 536 | "http://site.icu-project.org/">ICU4J</a> APIs in the Android framework under |
| 537 | the <code>android.icu</code> package. Migration is easy, and mostly entails |
| 538 | simply changing from the <code>com.java.icu</code> namespace to |
| 539 | <code>android.icu</code>. If you are already using an ICU4J bundle in your |
| 540 | apps, switching to the <code>android.icu</code> APIs provided in the Android |
| 541 | framework can produce substantial savings in APK size. |
| 542 | </p> |
| 543 | |
| 544 | <p> |
| 545 | To learn more about the Android ICU4J APIs, see <a href= |
| 546 | "{@docRoot}preview/features/icu4j-framework.html">ICU4J Support</a>. |
| 547 | </p> |
| 548 | |
| 549 | |
| 550 | |
Dirk Dougherty | cf65e484 | 2016-03-07 22:31:57 -0800 | [diff] [blame] | 551 | <h2 id="gles_32">OpenGL™ ES 3.2 API</h2> |
| 552 | |
| 553 | <p>Android N adds framework interfaces and platform support for OpenGL ES 3.2, including:</p> |
| 554 | |
| 555 | <ul> |
| 556 | <li> All extensions from the <a class="external-link" |
David Friedman | 182e8b5 | 2016-05-13 10:03:52 -0700 | [diff] [blame] | 557 | href="https://www.khronos.org/registry/gles/extensions/ANDROID/ANDROID_extension_pack_es31a.txt"> |
| 558 | Android Extension Pack</a></a> (AEP) except for <code>EXT_texture_sRGB_decode</code>. |
Dirk Dougherty | cf65e484 | 2016-03-07 22:31:57 -0800 | [diff] [blame] | 559 | <li> Floating-point framebuffers for HDR and deferred shading. |
| 560 | <li> BaseVertex draw calls to enable better batching and streaming. |
| 561 | <li> Robust buffer access control to reduce WebGL overhead. |
| 562 | </ul> |
| 563 | |
| 564 | <p>The framework API for OpenGL ES 3.2 on Android N is provided with the |
| 565 | <code>GLES32</code> class. When using OpenGL ES 3.2, be sure to declare the |
Andrew Solovay | 9b21857 | 2016-03-09 11:17:07 -0800 | [diff] [blame] | 566 | requirement in your manifest file, using the <code><uses-feature></code> tag and |
Dirk Dougherty | cf65e484 | 2016-03-07 22:31:57 -0800 | [diff] [blame] | 567 | the <code>android:glEsVersion</code> attribute. </p> |
| 568 | |
| 569 | <p>For information about using OpenGL ES, including how to check a device's |
| 570 | supported OpenGL ES version at runtime, see the <a |
| 571 | href="{@docRoot}guide/topics/graphics/opengl.html">OpenGL ES API guide</a>.</p> |
| 572 | |
| 573 | |
David Friedman | 82c668f | 2016-05-17 23:53:21 -0700 | [diff] [blame] | 574 | <h2 id="android_tv_recording">Android TV Recording</h2> |
Dirk Dougherty | 5942892 | 2016-03-10 18:54:49 -0800 | [diff] [blame] | 575 | |
| 576 | <p>Android N adds the ability to record and playback content from Android TV input |
| 577 | services via new recording APIs. Building on top of existing time-shifting |
| 578 | APIs, TV input services can control what channel data can be recorded, how |
| 579 | recorded sessions are saved, and manage user interaction with recorded content. </p> |
| 580 | |
| 581 | <p>For more information, see <a |
| 582 | href="{@docRoot}preview/features/tv-recording-api.html">Android TV Recording APIs</a>.</p> |
| 583 | |
| 584 | |
| 585 | <h2 id="android_for_work">Android for Work</h2> |
| 586 | |
| 587 | <p>Android for Work adds many new features and APIs for devices running Android N. |
Kevin Hufnagle | b6d1723 | 2016-03-22 11:29:03 -0700 | [diff] [blame] | 588 | Some highlights are below — for a complete list of changes, see |
| 589 | <a href="{@docRoot}preview/features/afw.html">Android for Work Updates</a>.</p> |
Dirk Dougherty | 5942892 | 2016-03-10 18:54:49 -0800 | [diff] [blame] | 590 | |
| 591 | <h3 id="work_profile_security_challenge">Work profile security challenge </h3> |
| 592 | |
| 593 | <p> |
Andrew Solovay | 097b115 | 2016-04-06 17:33:00 -0700 | [diff] [blame] | 594 | Profile owners targeting the N SDK |
| 595 | can specify a separate security challenge for apps running in |
Dirk Dougherty | 5942892 | 2016-03-10 18:54:49 -0800 | [diff] [blame] | 596 | the work profile. The work challenge is shown when a user attempts to open |
| 597 | any work apps. Successful completion of the security challenge unlocks the |
| 598 | work profile and decrypts it if necessary. For profile owners, |
| 599 | <code>ACTION_SET_NEW_PASSWORD</code> prompts the user to set a work |
| 600 | challenge, and <code>ACTION_SET_NEW_PARENT_PROFILE_PASSWORD</code> prompts |
| 601 | the user to set a device lock. |
| 602 | </p> |
| 603 | |
| 604 | <p> |
Andrew Solovay | 097b115 | 2016-04-06 17:33:00 -0700 | [diff] [blame] | 605 | Profile owners can set distinct passcode policies for the work challenge |
Dirk Dougherty | 5942892 | 2016-03-10 18:54:49 -0800 | [diff] [blame] | 606 | (such as how long the PIN needs to be, or whether a fingerprint can be used |
| 607 | to unlock the profile) using the <code>setPasswordQuality()</code>, |
| 608 | <code>setPasswordMinimumLength()</code> and related methods. The profile |
| 609 | owner can also set the device lock using the <code>DevicePolicyManager</code> |
| 610 | instance returned by the new <code>getParentProfileInstance()</code> method. |
| 611 | Additionally, profile owners can customize the credentials screen for the |
| 612 | work challenge using the new <code>setOrganizationColor()</code> and |
| 613 | <code>setOrganizationName()</code> methods. |
| 614 | </p> |
| 615 | <h3 id="turn_off_work">Turn off work </h3> |
| 616 | |
| 617 | <p>On a device with a work profile, users can toggle work mode. When work mode is |
| 618 | off the managed user is temporarily shut down, which disables work profile |
| 619 | apps, background sync, and notifications. This includes the profile owner |
| 620 | application. When work mode is off, the system displays a persistent status |
| 621 | icon to remind the user that they can't launch work apps. The launcher |
| 622 | indicates that work apps and widgets are not accessible. </p> |
| 623 | |
| 624 | <h3 id="always_on_vpn">Always on VPN </h3> |
| 625 | |
| 626 | <p>Device owners and profile owners can ensure that work apps always connect |
| 627 | through a specified VPN. The system automatically starts that VPN after the |
| 628 | device boots.</p> |
| 629 | |
| 630 | <p> |
| 631 | New <code>DevicePolicyManager</code> methods are |
| 632 | <code>setAlwaysOnVpnPackage()</code> and |
| 633 | <code>getAlwaysOnVpnPackage()</code>. |
| 634 | </p> |
| 635 | |
| 636 | <p>Because VPN services can be bound directly by the system without app |
| 637 | interaction, VPN clients need to handle new entry points for Always on VPN. As |
| 638 | before, services are indicated to the system by an intent filter matching |
| 639 | action <code>android.net.VpnService</code>. </p> |
| 640 | |
| 641 | <p> |
| 642 | Users can also manually set Always on VPN clients that implement |
| 643 | <code>VPNService</code> methods in the primary user using |
| 644 | <strong>Settings>More>Vpn</strong>. |
| 645 | </p> |
| 646 | |
Andrew Solovay | 097b115 | 2016-04-06 17:33:00 -0700 | [diff] [blame] | 647 | <h3 id="custom_provisioning">Customized provisioning</h3> |
| 648 | |
| 649 | <p> |
| 650 | An application can customize the profile owner and device owner provisioning |
| 651 | flows with corporate colors and logos. |
| 652 | <code>DevicePolicyManager.EXTRA_PROVISIONING_MAIN_COLOR</code> customizes |
| 653 | flow color. <code>DevicePolicyManager.EXTRA_PROVISIONING_LOGO_URI</code> |
| 654 | customizes the flow with a corporate logo. |
| 655 | </p> |
| 656 | |
David Friedman | 82c668f | 2016-05-17 23:53:21 -0700 | [diff] [blame] | 657 | <h2 id="accessibility_enhancements">Accessibility Enhancements</h2> |
Dirk Dougherty | 5942892 | 2016-03-10 18:54:49 -0800 | [diff] [blame] | 658 | |
| 659 | <p>Android N now offers Vision Settings directly on the Welcome screen for new |
| 660 | device setup. This makes it much easier for users to discover and configure |
| 661 | accessibility features on their devices, including magnification gesture, font |
| 662 | size, display size, and TalkBack. </p> |
| 663 | |
| 664 | <p>With these accessibility features getting more prominent placement, your users |
| 665 | are more likely to try your app with them enabled. Make sure you test your apps |
| 666 | early with these settings enabled. You can enable them from Settings > |
| 667 | Accessibility.</p> |
| 668 | |
| 669 | <p>Also in Android N, accessibility services can now help users with motor |
| 670 | impairments to touch the screen. The new API allows building services with |
| 671 | features such as face-tracking, eye-tracking, point scanning, and so on, to |
| 672 | meet the needs of those users.</p> |
| 673 | |
| 674 | <p>For more information, see <code>android.accessibilityservice.GestureDescription</code> |
Eric Schmidt | 57a83b5 | 2016-05-10 12:37:38 -0700 | [diff] [blame] | 675 | in the downloadable <a href="{@docRoot}preview/setup-sdk.html#docs-dl">API Reference</a>.</p> |
Dirk Dougherty | 5942892 | 2016-03-10 18:54:49 -0800 | [diff] [blame] | 676 | |
| 677 | |
David Friedman | 82c668f | 2016-05-17 23:53:21 -0700 | [diff] [blame] | 678 | <h2 id="direct_boot">Direct Boot</h2> |
Dirk Dougherty | 5942892 | 2016-03-10 18:54:49 -0800 | [diff] [blame] | 679 | |
| 680 | <p>Direct boot improves device startup times and lets registered |
| 681 | apps have limited functionality even after an unexpected reboot. |
| 682 | For example, if an encrypted device reboots while the user is sleeping, |
David Friedman | 93970ba | 2016-05-13 01:23:13 -0700 | [diff] [blame] | 683 | registered alarms, messages and incoming calls can now continue to notify |
Dirk Dougherty | 5942892 | 2016-03-10 18:54:49 -0800 | [diff] [blame] | 684 | the user as normal. This also means accessibility services can also be |
| 685 | available immediately after a restart.</p> |
| 686 | |
| 687 | <p>Direct boot takes advantage of file based encryption in Android N |
| 688 | to enable fine grained encryption policies for both system and app data. |
| 689 | The system uses a device-encrypted store for select system data and explicitly |
| 690 | registered app data. By default a credential-encrypted store is used for all |
| 691 | other system data, user data, apps, and app data. </p> |
| 692 | |
| 693 | <p>At boot, the system starts in a restricted mode with access to |
| 694 | device-encrypted data only, and without general access to apps or data. |
| 695 | If you have components that you want to run in this mode, you can register |
| 696 | them by setting a flag in the manifest. After restart, the system activates |
| 697 | registered components by broadcasting the <code>LOCKED_BOOT_COMPLETED</code> |
| 698 | intent. The system ensures registered device-encrypted app data is available |
| 699 | before unlock. All other data is unavailable until the User confirms their lock |
| 700 | screen credentials to decrypt it. </p> |
| 701 | |
| 702 | For more information, see <a href="{@docRoot}preview/features/direct-boot.html">Direct Boot</a>.</p> |
| 703 | </p> |
| 704 | |
Dirk Dougherty | 5942892 | 2016-03-10 18:54:49 -0800 | [diff] [blame] | 705 | <h2 id="key_attestation">Key Attestation</h2> |
| 706 | |
Kevin Hufnagle | 23239ca | 2016-06-09 16:02:31 -0700 | [diff] [blame] | 707 | <p> |
| 708 | Android N introduces <em>key attestation</em>, a new security tool that helps |
| 709 | you make sure that the key pairs stored within a device's <a class= |
| 710 | "external-link" href= |
| 711 | "https://source.android.com/security/keystore/"><em>hardware-backed |
| 712 | keystore</em></a> properly protect the sensitive information that your app |
| 713 | uses. By using this tool, you gain additional confidence that your app |
| 714 | interacts with keys that reside in secure hardware, even if the device |
| 715 | running your app is rooted. If you use keys from the hardware-backed keystore |
| 716 | in your apps, you should use this tool, particularly if you use the keys to |
| 717 | verify sensitive information within your app. |
| 718 | </p> |
Dirk Dougherty | 5942892 | 2016-03-10 18:54:49 -0800 | [diff] [blame] | 719 | |
Kevin Hufnagle | 23239ca | 2016-06-09 16:02:31 -0700 | [diff] [blame] | 720 | <p> |
| 721 | Key attestation allows you to verify that an RSA or EC key pair has been |
| 722 | created and stored in a device’s hardware-backed keystore within the device’s |
| 723 | trusted execution environment (TEE). The tool also allows you to use an |
| 724 | off-device service, such as your app's back-end server, to determine and |
| 725 | strongly verify the uses and validity of the key pair. These features provide |
| 726 | an additional level of security that protects the key pair, even if someone |
| 727 | roots the device or compromises the security of the Android platform running |
| 728 | on the device. |
| 729 | </p> |
Dirk Dougherty | 5942892 | 2016-03-10 18:54:49 -0800 | [diff] [blame] | 730 | |
Kevin Hufnagle | 23239ca | 2016-06-09 16:02:31 -0700 | [diff] [blame] | 731 | <p> |
| 732 | For more information, see the |
| 733 | <a href="{@docRoot}preview/features/key-attestation.html">Key Attestation</a> |
| 734 | developer documentation. |
| 735 | </p> |
Dirk Dougherty | 5942892 | 2016-03-10 18:54:49 -0800 | [diff] [blame] | 736 | |
| 737 | <h2 id="network_security_config">Network Security Config</h2> |
| 738 | |
| 739 | <p>In Android N, apps can customize the behavior of their secure (HTTPS, TLS) |
| 740 | connections safely, without any code modification, by using the declarative |
| 741 | <em>Network Security Config</em> instead of using the conventional |
| 742 | error-prone programmatic APIs (e.g. X509TrustManager).</p> |
| 743 | |
| 744 | <p>Supported features:</p> |
| 745 | <ul> |
| 746 | <li><b>Custom trust anchors.</b> Lets an application customize which |
| 747 | Certificate Authorities (CA) are trusted for its secure connections. For |
| 748 | example, trusting particular self-signed certificates or a restricted set of public CAs. |
| 749 | </li> |
| 750 | <li><b>Debug-only overrides.</b> Lets an application developer safely debug |
| 751 | secure connections of their application without added risk to the installed |
| 752 | base. |
| 753 | </li> |
| 754 | <li><b>Cleartext traffic opt-out.</b> Lets an application protect itself from |
| 755 | accidental usage of cleartext traffic.</li> |
| 756 | <li><b>Certificate pinning.</b> An advanced feature that lets an application |
| 757 | limit which server keys are trusted for secure connections.</li> |
| 758 | </ul> |
| 759 | |
| 760 | <p>For more information, see <a |
| 761 | href="{@docRoot}preview/features/security-config.html">Network Security |
| 762 | Config</a>.</p> |
| 763 | |
| 764 | <h2 id="default_trusted_ca">Default Trusted Certificate Authority</h2> |
| 765 | |
| 766 | <p>By default, apps that target Android N only trust system-provided certificates |
| 767 | and no longer trust user-added Certificate Authorities (CA). Apps targeting Android |
| 768 | N that wish to trust user-added CAs should use the |
| 769 | <a href="{@docRoot}preview/features/security-config.html">Network Security Config</a> to |
| 770 | specify how user CAs should be trusted.</p> |
| 771 | |
David Friedman | 82c668f | 2016-05-17 23:53:21 -0700 | [diff] [blame] | 772 | <h2 id="apk_signature_v2">APK Signature Scheme v2</h2> |
Dirk Dougherty | 5942892 | 2016-03-10 18:54:49 -0800 | [diff] [blame] | 773 | |
Kevin Hufnagle | 7cd4a10 | 2016-05-04 15:30:45 -0700 | [diff] [blame] | 774 | <p> |
| 775 | Android N introduces APK Signature Scheme v2, a new app-signing scheme that |
Kevin Hufnagle | aa1b7dd | 2016-05-11 17:38:45 -0700 | [diff] [blame] | 776 | offers faster app install times and more protection against unauthorized |
| 777 | alterations to APK files. By default, Android Studio 2.2 and the Android |
| 778 | Plugin for Gradle 2.2 sign your app using both APK Signature Scheme v2 and |
| 779 | the traditional signing scheme, which uses JAR signing. |
Kevin Hufnagle | 7cd4a10 | 2016-05-04 15:30:45 -0700 | [diff] [blame] | 780 | </p> |
Dirk Dougherty | 5942892 | 2016-03-10 18:54:49 -0800 | [diff] [blame] | 781 | |
Kevin Hufnagle | 7cd4a10 | 2016-05-04 15:30:45 -0700 | [diff] [blame] | 782 | <p> |
Kevin Hufnagle | aa1b7dd | 2016-05-11 17:38:45 -0700 | [diff] [blame] | 783 | Although we recommend applying APK Signature Scheme v2 to your app, this new |
| 784 | scheme is not mandatory. If your app doesn't build properly when using APK |
| 785 | Signature Scheme v2, you can disable the new scheme. The disabling process |
| 786 | causes Android Studio 2.2 and the Android Plugin for Gradle 2.2 to sign your |
| 787 | app using only the traditional signing scheme. To sign with only the |
| 788 | traditional scheme, open the module-level <code>build.gradle</code> file, then |
| 789 | add the line <code>v2SigningEnabled false</code> to your release signing |
| 790 | configuration: |
Kevin Hufnagle | 7cd4a10 | 2016-05-04 15:30:45 -0700 | [diff] [blame] | 791 | </p> |
Dirk Dougherty | 5942892 | 2016-03-10 18:54:49 -0800 | [diff] [blame] | 792 | |
Kevin Hufnagle | 7cd4a10 | 2016-05-04 15:30:45 -0700 | [diff] [blame] | 793 | <pre> |
| 794 | android { |
| 795 | ... |
| 796 | defaultConfig { ... } |
| 797 | signingConfigs { |
| 798 | release { |
| 799 | storeFile file("myreleasekey.keystore") |
| 800 | storePassword "password" |
| 801 | keyAlias "MyReleaseKey" |
| 802 | keyPassword "password" |
| 803 | <strong>v2SigningEnabled false</strong> |
| 804 | } |
| 805 | } |
| 806 | } |
| 807 | </pre> |
| 808 | |
Kevin Hufnagle | aa1b7dd | 2016-05-11 17:38:45 -0700 | [diff] [blame] | 809 | <p class="caution"><strong>Caution: </strong> If you sign your app using APK |
| 810 | Signature Scheme v2 and make further changes to the app, the app's signature |
| 811 | is invalidated. For this reason, use tools such as <code>zipalign</code> |
| 812 | before signing your app using APK Signature Scheme v2, not after. |
| 813 | </p> |
| 814 | |
Kevin Hufnagle | 7cd4a10 | 2016-05-04 15:30:45 -0700 | [diff] [blame] | 815 | <p> |
Kevin Hufnagle | aa1b7dd | 2016-05-11 17:38:45 -0700 | [diff] [blame] | 816 | For more information, read the Android Studio documents that describe how to |
smain@google.com | 73cf822 | 2016-05-19 16:30:43 -0700 | [diff] [blame] | 817 | <a href="{@docRoot}studio/publish/app-signing.html#release-mode"> |
Kevin Hufnagle | aa1b7dd | 2016-05-11 17:38:45 -0700 | [diff] [blame] | 818 | sign an app</a> in Android Studio and how to <a href= |
smain@google.com | 73cf822 | 2016-05-19 16:30:43 -0700 | [diff] [blame] | 819 | "{@docRoot}studio/build/build-variants.html#signing"> configure |
Kevin Hufnagle | aa1b7dd | 2016-05-11 17:38:45 -0700 | [diff] [blame] | 820 | the build file for signing apps</a> using the Android Plugin for Gradle. |
Kevin Hufnagle | 7cd4a10 | 2016-05-04 15:30:45 -0700 | [diff] [blame] | 821 | </p> |
Dirk Dougherty | 5942892 | 2016-03-10 18:54:49 -0800 | [diff] [blame] | 822 | |
David Friedman | 82c668f | 2016-05-17 23:53:21 -0700 | [diff] [blame] | 823 | <h2 id="scoped_directory_access">Scoped Directory Access</h2> |
Dirk Dougherty | 5942892 | 2016-03-10 18:54:49 -0800 | [diff] [blame] | 824 | |
| 825 | <p>In Android N, apps can use new APIs to request access to specific <a |
| 826 | href="{@docRoot}guide/topics/data/data-storage.html#filesExternal">external |
| 827 | storage</a> directories, including directories on removable media such as SD |
| 828 | cards. The new APIs greatly simplify how your application accesses standard |
| 829 | external storage directories, such as the <code>Pictures</code> directory. Apps |
| 830 | like photo apps can use these APIs instead of using |
| 831 | <code>READ_EXTERNAL_STORAGE</code>, which grants access to all storage |
| 832 | directories, or the Storage Access Framework, which makes the user navigate to |
| 833 | the directory.</p> |
| 834 | |
| 835 | <p>Additionally, the new APIs simplify the steps a user takes to grant external |
| 836 | storage access to your app. When you use the new APIs, the system uses a simple |
| 837 | permissions UI that clearly details what directory the application is |
| 838 | requesting access to.</p> |
| 839 | |
| 840 | <p>For more information, see the |
| 841 | <a href="{@docRoot}preview/features/scoped-folder-access.html">Scoped |
| 842 | Directory Access</a> developer documentation.</p> |
| 843 | |
David Friedman | 93970ba | 2016-05-13 01:23:13 -0700 | [diff] [blame] | 844 | <h2 id="keyboard_shortcuts_helper">Keyboard Shortcuts Helper</h2> |
| 845 | |
| 846 | <p> |
Hemal Patel | dd4a8e7 | 2016-06-07 18:22:21 -0700 | [diff] [blame] | 847 | In Android N, the user can press <strong>Meta + /</strong> to trigger a |
| 848 | <em>Keyboard Shortcuts</em> screen that displays all shortcuts available both |
| 849 | from the system and from the app in focus. The system retrieves these |
| 850 | shortcuts automatically from the app’s menu if the shortcuts exist. You can |
| 851 | also provide your own fine-tuned shortcuts lists for the screen. You can do |
| 852 | this by overriding the new <code>Activity.onProvideKeyboardShortcuts()</code> |
| 853 | method, described in the downloadable <a href= |
| 854 | "{@docRoot}preview/setup-sdk.html#docs-dl">API Reference</a>. |
| 855 | </p> |
| 856 | |
| 857 | <p class="note"> |
| 858 | <strong>Note:</strong> The <strong>Meta</strong> key is not present on all |
| 859 | keyboards: on a Macintosh keyboard, it is the <strong>Command</strong> key, |
| 860 | on the Windows keyboard, it is the <strong>Windows</strong> key, and on the |
| 861 | Pixel C and the Chrome OS keyboards, it is the <strong>Search</strong> key. |
David Friedman | 93970ba | 2016-05-13 01:23:13 -0700 | [diff] [blame] | 862 | </p> |
| 863 | |
David Friedman | 93970ba | 2016-05-13 01:23:13 -0700 | [diff] [blame] | 864 | <p> |
Hemal Patel | dd4a8e7 | 2016-06-07 18:22:21 -0700 | [diff] [blame] | 865 | To trigger Keyboard Shortcuts Helper from anywhere in your app, call |
| 866 | {@code Activity.requestKeyboardShortcutsHelper()} for the relevant activity. |
David Friedman | 93970ba | 2016-05-13 01:23:13 -0700 | [diff] [blame] | 867 | </p> |
| 868 | |
Hemal Patel | 37663db | 2016-06-13 14:37:36 -0700 | [diff] [blame^] | 869 | <h2 id="custom_pointer_api"> |
| 870 | Custom Pointer API |
| 871 | </h2> |
| 872 | |
| 873 | <p> |
| 874 | Android N introduces the Custom Pointer API, which lets you customize the |
| 875 | appearance, visibility, and behavior of the pointer. This capability is |
| 876 | especially useful when a user is using a mouse or touchpad to interact with |
| 877 | UI objects. The default pointer uses a standard icon. This API also includes |
| 878 | advanced functionality such as changing the pointer icon's appearance based |
| 879 | on specific mouse or touchpad movements. |
| 880 | </p> |
| 881 | |
| 882 | <p> |
| 883 | To set a pointer icon, override the <code>onResolvePointerIcon()</code> |
| 884 | method of the <code>View</code> class. This method uses a |
| 885 | <code>PointerIcon</code> object to draw the icon that corresponds to a |
| 886 | specific motion event. |
| 887 | </p> |
| 888 | |
David Friedman | 93970ba | 2016-05-13 01:23:13 -0700 | [diff] [blame] | 889 | <h2 id="sustained_performance_api">Sustained Performance API</h2> |
| 890 | |
| 891 | <p> |
| 892 | Performance can fluctuate dramatically for long-running apps, because the |
| 893 | system throttles system-on-chip engines as device components reach their |
| 894 | temperature limits. This fluctuation presents a moving target for app |
| 895 | developers creating high-performance, long-running apps. |
| 896 | </p> |
| 897 | |
| 898 | <p> |
| 899 | To address these limitations, Android N includes support for |
David Friedman | 182e8b5 | 2016-05-13 10:03:52 -0700 | [diff] [blame] | 900 | <em>sustained performance mode</em>, enabling OEMs to provide hints about |
| 901 | device-performance capabilities for long-running apps. App developers |
| 902 | can use these hints to tune apps for a predictable, |
David Friedman | 93970ba | 2016-05-13 01:23:13 -0700 | [diff] [blame] | 903 | consistent level of device performance over long periods of time. |
| 904 | </p> |
| 905 | |
| 906 | <p> |
| 907 | App developers can try out this new API in the N Developer Preview on |
| 908 | Nexus 6P devices only. To use this feature, |
| 909 | set the sustained performance window flag for the window |
| 910 | you want to run in sustained performance mode. Set this flag using the |
David Friedman | 182e8b5 | 2016-05-13 10:03:52 -0700 | [diff] [blame] | 911 | {@code Window.setSustainedPerformanceMode()} method. The system automatically |
David Friedman | 93970ba | 2016-05-13 01:23:13 -0700 | [diff] [blame] | 912 | disables this mode when the window is no longer in focus. |
| 913 | </p> |
| 914 | |
David Friedman | 182e8b5 | 2016-05-13 10:03:52 -0700 | [diff] [blame] | 915 | <h2 id="vr">VR Support</h2> |
| 916 | |
| 917 | <p> |
David Friedman | 2023739 | 2016-05-17 15:31:25 -0700 | [diff] [blame] | 918 | Android N adds platform support and optimizations for a new VR Mode to let developers |
| 919 | build high-quality mobile VR experiences for users. There are a number of performance |
| 920 | enhancements, including access to an exclusive CPU core for VR apps. |
| 921 | Within your apps, you can take advantage of intelligent head-tracking, |
| 922 | and stereo notifications that work for VR. Most importantly, Android N provides for |
| 923 | very low latency graphics. For complete information about building VR apps for Android N, |
| 924 | see the <a href="https://developers.google.com/vr/android/">Google VR SDK for Android</a>. |
| 925 | </p> |
David Friedman | 182e8b5 | 2016-05-13 10:03:52 -0700 | [diff] [blame] | 926 | |
| 927 | |
Andrew Solovay | 097b115 | 2016-04-06 17:33:00 -0700 | [diff] [blame] | 928 | <h2 id="print_svc">Print Service Enhancements</h2> |
| 929 | |
| 930 | <p> |
| 931 | In Android N, print service developers can now surface additional information |
| 932 | about individual printers and print jobs. |
| 933 | </p> |
| 934 | |
| 935 | <p> |
| 936 | When listing individual printers, a print service can now set per-printer |
| 937 | icons in two ways: |
| 938 | </p> |
| 939 | |
| 940 | <ul> |
| 941 | <li>You can set an icon from a resource ID by calling |
| 942 | <code>PrinterInfo.Builder.setResourceIconId()</code> |
| 943 | </li> |
| 944 | |
| 945 | <li>You can show an icon from the network by calling |
| 946 | <code>PrinterInfo.Builder.setHasCustomPrinterIcon()</code>, and setting a |
| 947 | callback for when the icon is requested using |
| 948 | <code>android.printservice.PrinterDiscoverySession.onRequestCustomPrinterIcon()</code> |
| 949 | </li> |
| 950 | </ul> |
| 951 | |
| 952 | <p> |
| 953 | In addition, you can provide a per-printer activity to display additional |
| 954 | information by calling <code>PrinterInfo.Builder.setInfoIntent()</code>. |
| 955 | </p> |
| 956 | |
| 957 | <p> |
| 958 | You can indicate the progress and status of print jobs in the print job |
| 959 | notification by calling |
| 960 | <code>android.printservice.PrintJob.setProgress()</code> and |
| 961 | <code>android.printservice.PrintJob.setStatus()</code>, respectively. |
| 962 | </p> |
| 963 | |
| 964 | <p> |
| 965 | For more information about these methods, see the downloadable <a href= |
| 966 | "{@docRoot}preview/setup-sdk.html#docs-dl">API Reference</a>. |
| 967 | </p> |
Eric Schmidt | 186fada | 2016-04-27 11:48:22 -0700 | [diff] [blame] | 968 | |
David Friedman | 93970ba | 2016-05-13 01:23:13 -0700 | [diff] [blame] | 969 | <h2 id="framemetrics_api">FrameMetricsListener API</h2> |
| 970 | |
| 971 | <p> |
| 972 | The FrameMetricsListener API allows an app to monitor its UI rendering |
David Friedman | 182e8b5 | 2016-05-13 10:03:52 -0700 | [diff] [blame] | 973 | performance. The API provides this capability by exposing a streaming Pub/Sub API to transfer frame |
David Friedman | 93970ba | 2016-05-13 01:23:13 -0700 | [diff] [blame] | 974 | timing info for the app's current window. The data returned is |
David Friedman | 2023739 | 2016-05-17 15:31:25 -0700 | [diff] [blame] | 975 | equivalent to that which <code><a href="{@docRoot}tools/help/shell.html#shellcommands">adb shell</a> |
| 976 | dumpsys gfxinfo framestats</code> displays, but is not limited to the past 120 frames. |
David Friedman | 93970ba | 2016-05-13 01:23:13 -0700 | [diff] [blame] | 977 | </p> |
| 978 | |
| 979 | <p> |
| 980 | You can use FrameMetricsListener to measure interaction-level UI |
| 981 | performance in production, without a USB connection. This API |
| 982 | allows collection of data at a much higher granularity than does |
| 983 | {@code adb shell dumpsys gfxinfo}. This higher granularity is possible because |
| 984 | the system can collect data for particular interactions in the app; the system |
| 985 | need not capture a global summary of the entire app’s |
| 986 | performance, or clear any global state. You can use this |
| 987 | capability to gather performance data and catch regressions in UI performance |
| 988 | for real use cases within an app. |
| 989 | </p> |
| 990 | |
| 991 | <p> |
David Friedman | 182e8b5 | 2016-05-13 10:03:52 -0700 | [diff] [blame] | 992 | To monitor a window, implement the <code>FrameMetricsListener.onMetricsAvailable()</code> |
| 993 | callback method and register it on that window. For more information, refer to |
| 994 | the {@code FrameMetricsListener} class documentation in |
| 995 | the downloadable <a href="{@docRoot}preview/setup-sdk.html#docs-dl">API Reference</a>. |
David Friedman | 93970ba | 2016-05-13 01:23:13 -0700 | [diff] [blame] | 996 | </p> |
| 997 | |
David Friedman | 93970ba | 2016-05-13 01:23:13 -0700 | [diff] [blame] | 998 | <p> |
David Friedman | 182e8b5 | 2016-05-13 10:03:52 -0700 | [diff] [blame] | 999 | The API provides a {@code FrameMetrics} object, which contains timing data that |
David Friedman | 93970ba | 2016-05-13 01:23:13 -0700 | [diff] [blame] | 1000 | the rendering subsystem reports for various milestones in a frame lifecycle. |
| 1001 | The supported metrics are: {@code UNKNOWN_DELAY_DURATION}, |
| 1002 | {@code INPUT_HANDLING_DURATION}, {@code ANIMATION_DURATION}, |
| 1003 | {@code LAYOUT_MEASURE_DURATION}, {@code DRAW_DURATION}, {@code SYNC_DURATION}, |
| 1004 | {@code COMMAND_ISSUE_DURATION}, {@code SWAP_BUFFERS_DURATION}, |
David Friedman | 182e8b5 | 2016-05-13 10:03:52 -0700 | [diff] [blame] | 1005 | {@code TOTAL_DURATION}, and {@code FIRST_DRAW_FRAME}. |
David Friedman | 93970ba | 2016-05-13 01:23:13 -0700 | [diff] [blame] | 1006 | </p> |
| 1007 | |
| 1008 | |
Eric Schmidt | 186fada | 2016-04-27 11:48:22 -0700 | [diff] [blame] | 1009 | <h2 id="virtual_files">Virtual Files</h2> |
| 1010 | |
| 1011 | <p> |
| 1012 | In previous versions of Android, your app could use the Storage Access |
| 1013 | Framework to allow users to select files from their cloud storage accounts, |
| 1014 | such as Google Drive. However, there was no way to represent files that did |
| 1015 | not have a direct bytecode representation; every file was required to provide |
| 1016 | an input stream. |
| 1017 | </p> |
| 1018 | |
| 1019 | <p> |
| 1020 | Android N adds the concept of <em>virtual files</em> to the Storage Access |
| 1021 | Framework. The virtual files feature allows your |
| 1022 | {@link android.provider.DocumentsProvider} to return document URIs that can be |
| 1023 | used with an {@link android.content.Intent#ACTION_VIEW} intent even if they |
| 1024 | don't have a direct bytecode representation. Android N also allows you to |
| 1025 | provide alternate formats for user files, virtual or otherwise. |
| 1026 | </p> |
| 1027 | |
| 1028 | <p> |
| 1029 | To get a URI for a virtual document in your app, first you create an |
| 1030 | {@link android.content.Intent} to open the file picker UI. Since an app |
| 1031 | cannot directly open a virtual file by using the |
| 1032 | {@link android.content.ContentResolver#openInputStream(Uri) openInputStream()} |
| 1033 | method, your app does not receive any virtual files if you include the |
| 1034 | {@link android.content.Intent#CATEGORY_OPENABLE} category. |
| 1035 | </p> |
| 1036 | |
| 1037 | <p> |
| 1038 | After the user has made a selection, the system calls the |
| 1039 | {@link android.app.Activity#onActivityResult onActivityResult()} method. |
| 1040 | Your app can retrieve the URI of the virtual file and get an input stream, as |
| 1041 | demonstrated in the code snippet below. |
| 1042 | </p> |
| 1043 | |
| 1044 | <pre> |
| 1045 | // Other Activity code ... |
| 1046 | |
| 1047 | final static private int REQUEST_CODE = 64; |
| 1048 | |
| 1049 | // We listen to the OnActivityResult event to respond to the user's selection. |
| 1050 | @Override |
| 1051 | public void onActivityResult(int requestCode, int resultCode, |
| 1052 | Intent resultData) { |
| 1053 | try { |
| 1054 | if (requestCode == REQUEST_CODE && |
| 1055 | resultCode == Activity.RESULT_OK) { |
| 1056 | |
| 1057 | Uri uri = null; |
| 1058 | |
| 1059 | if (resultData != null) { |
| 1060 | uri = resultData.getData(); |
| 1061 | |
| 1062 | ContentResolver resolver = getContentResolver(); |
| 1063 | |
| 1064 | // Before attempting to coerce a file into a MIME type, |
| 1065 | // check to see what alternative MIME types are available to |
| 1066 | // coerce this file into. |
| 1067 | String[] streamTypes = |
| 1068 | resolver.getStreamTypes(uri, "*/*"); |
| 1069 | |
| 1070 | AssetFileDescriptor descriptor = |
| 1071 | resolver.openTypedAssetFileDescriptor( |
| 1072 | uri, |
| 1073 | streamTypes[0], |
| 1074 | null); |
| 1075 | |
| 1076 | // Retrieve a stream to the virtual file. |
| 1077 | InputStream inputStream = descriptor.createInputStream(); |
| 1078 | } |
| 1079 | } |
| 1080 | } catch (Exception ex) { |
| 1081 | Log.e("EXCEPTION", "ERROR: ", ex); |
| 1082 | } |
| 1083 | } |
| 1084 | </pre> |
| 1085 | |
| 1086 | <p> |
| 1087 | For more information about accessing user files, see the |
| 1088 | <a href="{@docRoot}guide/topics/providers/document-provider.html">Storage |
| 1089 | Access Frameworks guide</a>. |
Eric Schmidt | 1231768 | 2016-05-10 08:40:53 -0700 | [diff] [blame] | 1090 | </p> |