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