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