android-5.0.jd revision 7b4e310de97fea3deddddb6ee1c1f6d8922f13e2
1page.title=Android 5.0 APIs 2excludeFromSuggestions=true 3sdk.platform.version=5.0 4sdk.platform.apiLevel=21 5@jd:body 6 7 8<div id="qv-wrapper"> 9<div id="qv"> 10 11<h2>In this document 12 <a href="#" onclick="hideNestedItems('#toc44',this);return false;" class="header-toggle"> 13 <span class="more">show more</span> 14 <span class="less" style="display:none">show less</span></a></h2> 15 16<ol id="toc44" class="hide-nested"> 17 <li><a href="#ApiLevel">Update your target API level</a></li> 18 <li><a href="#Behaviors">Important Behavior Changes</a> 19 <ol> 20 <li><a href="#ART">If you haven't tested your app against the new Android Runtime (ART)...</a></li> 21 <li><a href="#BehaviorNotifications">If your app implements notifications...</a></li> 22 <li><a href="#BehaviorMediaControl">If your app uses RemoteControlClient...</a></li> 23<li><a href="#BehaviorGetRecentTasks">If your app uses getRecentTasks()...</a></li> 24<li><a href="#64BitSupport">If you are using the Android Native Development Kit (NDK)...</a></li> 25<li><a href="#BindService">If your app binds to a Service...</a></li> 26 </ol> 27 </li> 28 <li><a href="#UI">User Interface</a> 29 <ol> 30 <li><a href="#MaterialDesign">Material design support</a></li> 31 <li><a href="#Recents">Concurrent documents and activities in the recents screen</a></li> 32 <li><a href="#WebView">WebView updates</a></li> 33 <li><a href="#ScreenCapture">Screen capturing and sharing</a></li> 34 </ol> 35 </li> 36 <li><a href="#Notifications">Notifications</a> 37 <ol> 38 <li><a href="#LockscreenNotifications">Lock screen notifications</a></li> 39 <li><a href="#NotificationsMetadata">Notifications metadata</a></li> 40 </ol> 41 </li> 42 <li><a href="#Graphics">Graphics</a> 43 <ol> 44 <li><a href="#OpenGLES-3-1">Support for OpenGL ES 3.1</a></li> 45 <li><a href="#AndroidExtensionPack">Android Extension Pack</a></li> 46 </ol> 47 </li> 48 <li><a href="#Media">Media</a> 49 <ol> 50 <li><a href="#Camera-v2">Camera API for advanced camera capabilities</a></li> 51 <li><a href="#AudioPlayback">Audio playback</a></li> 52 <li><a href="#MediaPlaybackControl">Media playback control</a></li> 53 <li><a href="#MediaBrowsing">Media browsing</a></li> 54 </ol> 55 </li> 56 <li><a href="#Storage">Storage</a> 57 <ol> 58 <li><a href="#DirectorySelection">Directory selection</a></li> 59 </ol> 60 </li> 61 <li><a href="#Wireless">Wireless and Connectivity</a> 62 <ol> 63 <li><a href="#Multinetwork">Multiple network connections</a></li> 64 <li><a href="#BluetoothBroadcasting">Bluetooth broadcasting</a></li> 65 <li><a href="#NFCEnhancements">NFC enhancements</a></li> 66 </ol> 67 </li> 68 <li><a href="#Power">Project Volta</a> 69 <ol> 70 <li><a href="#JobScheduler">Scheduling jobs</a></li> 71 <li><a href="#PowerMeasurementTools">Developer tools for battery usage</a> 72 </ol> 73 </li> 74 <li><a href="#Enterprise">Android in the Workplace and in Education</a> 75 <ol> 76 <li><a href="#ManagedProvisioning">Managed provisioning</a></li> 77 <li><a href="#DeviceOwner">Device owner</a></li> 78 <li><a href="#ScreenPinning">Screen pinning</a></li> 79 </ol> 80 </li> 81 <li><a href="#System">System</a> 82 <ol> 83 <li><a href="#AppUsageStatistics">App usage statistics</a></li> 84 </ol> 85 </li> 86 <li><a href="#Printing">Printing Framework</a> 87 <ol> 88 <li><a href="#PDFRender">Render PDF as bitmap</a></li> 89 </ol> 90 </li> 91 <li><a href="#TestingA11y">Testing & Accessibility</a> 92 <ol> 93 <li><a href="#TestingA11yImprovements">Testing and accessibility improvements</a></li> 94 </ol> 95 </li> 96 <li><a href="#IME">IME</a> 97 <ol> 98 <li><a href="#Switching">Easier switching between input languages</a></li> 99 </ol> 100 </li> 101 <li><a href="#Manifest">Manifest Declarations</a> 102 <ol> 103 <li><a href="#ManifestFeatures">Declarable required features</a></li> 104 <li><a href="#Permissions">User permissions</a></li> 105 </ol> 106 </li> 107</ol> 108 109<h2>API Differences</h2> 110<ol> 111<li><a href="{@docRoot}sdk/api_diff/21/changes.html">API level 20 to 21 »</a> </li> 112<li><a href="{@docRoot}sdk/api_diff/preview-21/changes.html">L Developer Preview to 21 »</a> </li> 113</ol> 114 115</div> 116</div> 117 118<p>API Level: {@sdkPlatformApiLevel}</p> 119 120<p>Android 5.0 (<a href="{@docRoot}reference/android/os/Build.VERSION_CODES.html#LOLLIPOP">LOLLIPOP</a>) 121 offers new features for users and app developers. This document provides an 122 introduction to the most notable new APIs.</p> 123 124 125<h3 id="Start">Start developing</h3> 126 127<p>To start building apps for Android 5.0, you must first <a href="{@docRoot}sdk/index.html">get 128the Android SDK</a>. Then use the <a href="{@docRoot}tools/help/sdk-manager.html">SDK Manager</a> 129to download the Android 5.0 SDK Platform and System Images.</p> 130 131<p style=" 132 padding: 10px; 133 background: #eee; 134 width: 445px; 135 border: 1px solid #ccc; 136 margin-top: 20px; 137">To test your apps on a real device, flash a Nexus 5 or Nexus 7 with the <br> 138<a href="/preview/index.html#Start"><b>ANDROID PREVIEW SYSTEM IMAGE</b></a>.</p> 139 140 141 142<h3 id="ApiLevel">Update your target API level</h3> 143 144<p>To better optimize your app for devices running Android {@sdkPlatformVersion}, 145 set your <a 146href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#target">{@code targetSdkVersion}</a> to 147<code>"{@sdkPlatformApiLevel}"</code>, install your app on an Android 148{@sdkPlatformVersion} system image, test it, then publish the updated app with 149this change.</p> 150 151<p>You can use Android {@sdkPlatformVersion} APIs while also supporting older 152versions by adding conditions to your code that check for the system API level 153before executing APIs not supported by your <a 154href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#min">{@code minSdkVersion}</a>. 155To learn more about maintaining backward compatibility, read <a 156href="{@docRoot}training/basics/supporting-devices/platforms.html">Supporting 157Different Platform Versions</a>.</p> 158 159<p>For more information about how API levels work, read <a 160href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#ApiLevels">What is API 161Level?</a></p> 162 163<h2 id="Behaviors">Important Behavior Changes</h2> 164 165<p>If you have previously published an app for Android, be aware that your app 166 might be affected by changes in Android 5.0.</p> 167 168<h3 id="ART">If you haven't tested your app against the new Android Runtime (ART)...</h3> 169 170<p>The 4.4 release introduced a new, experimental Android runtime, ART. Under 1714.4, ART was optional, and the default runtime remained Dalvik. With Android 1725.0, ART is now the default runtime.</p> 173 174<p>For an overview of ART's new features, see 175<a href="https://source.android.com/devices/tech/dalvik/art.html">Introducing 176ART</a>. Some of the major new features are:</p> 177 178<ul> 179 <li>Ahead-of-time (AOT) compilation</li> 180 <li>Improved garbage collection (GC)</li> 181 <li>Improved debugging support</li> 182</ul> 183 184<p>Most Android apps should just work without any changes under ART. However, some 185techniques that work on Dalvik do not work on ART. For information about the 186most important issues, see 187<a href="{@docRoot}guide/practices/verifying-apps-art.html">Verifying App 188Behavior on the Android Runtime (ART)</a>. Pay particular attention if:</p> 189 190<ul> 191 <li>Your app uses Java Native Interface (JNI) to run C/C++ code.</li> 192 <li>You use development tools that generate non-standard code (such as some 193 obfuscators).</li> 194 <li>You use techniques that are incompatible with compacting garbage 195 collection. (ART does not currently implement compacting GC, but 196 compacting GC is under development in the Android Open Source 197 Project.)</li> 198</ul> 199 200<h3 id="BehaviorNotifications">If your app implements notifications...</h3> 201 202<p>Make sure your notifications take these Android 5.0 changes into account. 203 To learn more about designing your notifications for Android 5.0 and higher, 204 see the <a href="{@docRoot}design/patterns/notifications.html">notifications design guide</a>. 205</p> 206 207<h4 id="NotificationsMaterialDesignStyle">Material design style</h4> 208<p>Notifications are drawn with dark text atop white (or very light) backgrounds 209 to match the new material design widgets. Make sure that all your 210 notifications look right with the new color scheme. If your notifications 211look wrong, fix them:</p> 212 213<ul> 214 <li>Use {@link android.app.Notification.Builder#setColor(int) setColor()} 215 to set an accent color in a circle behind your icon image. </li> 216 <li>Update or remove assets that involve color. The system ignores all 217 non-alpha channels in action icons and in the main notification icon. You 218 should assume that these icons will be alpha-only. The system draws 219 notification icons in white and action icons in dark gray.</li> 220</ul> 221 222<h4 id="NotificationsSoundVibration">Sound and vibration</h4> 223<p>If you are currently adding sounds and vibrations to your notifications by 224using the {@link android.media.Ringtone}, {@link android.media.MediaPlayer}, 225or {@link android.os.Vibrator} classes, remove this code so that 226the system can present notifications correctly in 227<em>priority</em> mode. Instead, use 228{@link android.app.Notification.Builder} methods to add sounds and 229vibration.</p> 230 231<p>Setting the device to 232{@link android.media.AudioManager#RINGER_MODE_SILENT RINGER_MODE_SILENT} now 233causes the device to enter the new priority mode. The device leaves priority 234mode if you set it to 235{@link android.media.AudioManager#RINGER_MODE_NORMAL RINGER_MODE_NORMAL} or 236{@link android.media.AudioManager#RINGER_MODE_NORMAL RINGER_MODE_VIBRATE}.</p> 237 238<p>Previously, Android used {@link android.media.AudioManager#STREAM_MUSIC STREAM_MUSIC} 239as the master stream to control volume on tablet devices. In Android 5.0, the 240master volume stream for both phone and tablet devices is now unified, and 241is controlled by {@link android.media.AudioManager#STREAM_RING STREAM_RING} or 242{@link android.media.AudioManager#STREAM_NOTIFICATION STREAM_NOTIFICATION}.</p> 243 244<h4 id="NotificationsLockscreenVisibility">Lock screen visibility</h4> 245<p>By default, notifications now appear on the user's lock screen in Android 5.0. 246Users can choose to protect sensitive information from being exposed, in which 247case the system automatically redacts the text displayed by the notification. To 248customize this redacted notification, use 249{@link android.app.Notification.Builder#setPublicVersion(android.app.Notification) 250 setPublicVersion()}.</p> 251<p>If the notification does not contain personal information, or if you want to 252allow media playback control on the notification, call the 253{@link android.app.Notification.Builder#setVisibility(int) setVisibility()} 254method and set the notification's visibility level to 255{@link android.app.Notification#VISIBILITY_PUBLIC VISIBILITY_PUBLIC}. 256</p> 257 258<div class="figure" style="width:320px"> 259 <img src="{@docRoot}images/android-5.0/hun-example.png" 260 srcset="{@docRoot}images/android-5.0/hun-example@2x.png 2x" 261 alt="" width="320" height="541" id="figure1" /> 262 <p class="img-caption"> 263 <strong>Figure 1.</strong> Fullscreen activity showing a heads-up notification 264 </p> 265</div> 266 267<h4 id="NotificationsMediaPlayback">Media playback</h4> 268<p>If you are implementing notifications that present media playback 269status or transport controls, consider using the new 270{@link android.app.Notification.MediaStyle} template instead of a custom 271{@link android.widget.RemoteViews.RemoteView} object. Whichever approach you 272choose, make sure to set the notification's visibility to 273{@link android.app.Notification#VISIBILITY_PUBLIC VISIBILITY_PUBLIC} so that 274your controls are accessible from the lock screen. Note that beginning in 275Android 5.0, the system no longer shows 276{@link android.media.RemoteControlClient} objects on the lock screen. For more 277information, see 278<a href="#BehaviorMediaControl">If your app uses RemoteControlClient</a>.</p> 279 280<h4 id="NotificationsHeadsup">Heads-up notification</h4> 281<p>Notifications may now appear in a small floating window (also called a 282 heads-up notification) when the device is active (that is, the device is 283 unlocked and its screen is on). These notifications appear similar to the 284 compact form of your notification, except that the heads-up notification also 285 shows action buttons. Users can act on, or dismiss, a heads-up notification 286 without leaving the current app.</p> 287 288<p>Examples of conditions that may trigger heads-up notifications include:</p> 289 290<ul> 291 <li>The user's activity is in fullscreen mode (the app uses 292{@link android.app.Notification#fullScreenIntent})</li> 293 <li>The notification has high priority and uses ringtones or vibrations</li> 294</ul> 295 296<p>If your app implements notifications under any of those scenarios, make sure 297that heads-up notifications are presented correctly.</p> 298 299<h3 id="BehaviorMediaControl">If your app uses RemoteControlClient...</h3> 300<p>The {@link android.media.RemoteControlClient} class is now deprecated. Switch 301 to the new {@link android.media.session.MediaSession} API as 302 soon as possible.</p> 303 304<p>Lock screens in Android 5.0 do not show transport controls for 305your {@link android.media.session.MediaSession} or 306{@link android.media.RemoteControlClient}. Instead, your app can provide 307media playback control from the lock screen through a notification. This 308gives your app more control over the presentation of media buttons, while 309providing a consistent experience for users across locked and 310unlocked devices.</p> 311 312<p>Android 5.0 introduces a new 313{@link android.app.Notification.MediaStyle} template for this purpose. 314{@link android.app.Notification.MediaStyle} converts notification 315actions that you added with 316{@link android.app.Notification.Builder#addAction(int, java.lang.CharSequence, 317 android.app.PendingIntent) 318Notification.Builder.addAction()} into compact buttons embedded in your app's 319media playback notifications. Pass your session token to the 320{@link android.app.Notification.MediaStyle#setMediaSession(android.media.session.MediaSession.Token) 321 setSession()} method to inform the system that this notification controls an 322 ongoing media session.</p> 323 324<p>Make sure to set the notification's visibility to 325 {@link android.app.Notification#VISIBILITY_PUBLIC VISIBILITY_PUBLIC} 326 to mark the notification as safe to show on any lock screen (secure or 327 otherwise). For more information, see 328 <a href="#LockscreenNotifications">Lock screen notifications</a>.</p> 329 330<p>To display media playback controls if your app is running on the 331Android <a href="{@docRoot}tv/index.html">TV</a> or 332<a href="{@docRoot}wear/index.html">Wear</a> platform, implement the 333{@link android.media.session.MediaSession} class. You should also implement 334{@link android.media.session.MediaSession} if your app needs to receive media 335button events on Android devices.</p> 336 337<h3 id="BehaviorGetRecentTasks">If your app uses getRecentTasks()...</h3> 338 339<p>With the introduction of the new <em>concurrent documents and activities 340tasks</em> feature in Android 5.0 (see <a href="#Recents">Concurrent 341documents and activities in the recents screen</a> below), 342the {@link android.app.ActivityManager#getRecentTasks 343ActivityManager.getRecentTasks()} method is now deprecated to improve user 344privacy. For backward compatibility, this method still returns a small subset of 345its data, including the calling application’s own tasks and possibly some other 346non-sensitive tasks (such as Home). If your app is using this method to retrieve 347its own tasks, use {@link android.app.ActivityManager#getAppTasks() getAppTasks()} 348instead to retrieve that information.</p> 349 350<h3 id="64BitSupport">If you are using the Android Native Development Kit (NDK)...</h3> 351 352<p>Android 5.0 introduces support for 64-bit systems. The 64-bit enhancement 353 increases address space and improves performance, while still supporting 354 existing 32-bit apps fully. The 64-bit support also improves the performance of 355 OpenSSL for cryptography. In addition, this release introduces new native 356 media NDK APIs, as well as native OpenGL ES (GLES) 3.1 support.</p> 357 358<p>To use the 64-bit support provided in Android 5.0, download and install NDK 359 Revision 10c from the 360<a href="{@docRoot}tools/sdk/ndk/index.html">Android NDK page</a>. Refer to the 361Revision 10c <a href="{@docRoot}tools/sdk/ndk/index.html#Revisions">release notes</a> 362for more information about important changes and bug fixes to the NDK.</p> 363 364<h3 id="BindService">If your app binds to a Service...</h3> 365 366<p>The 367 {@link android.content.Context#bindService(android.content.Intent, android.content.ServiceConnection, int) Context.bindService()} 368 method now requires an explicit {@link android.content.Intent}, 369and throws an exception if given an implicit intent. 370To ensure your app is secure, use an explicit intent when starting or binding 371your {@link android.app.Service}, and do not declare intent filters for the service.</p> 372 373<h2 id="UI">User Interface</h2> 374 375<h3 id="MaterialDesign">Material design support</h3> 376 377<p>The upcoming release adds support for Android's new <em>material design</em> 378style. You can create apps with material design that are visually dynamic and 379have UI element transitions that feel natural to users. This support includes:</p> 380 381<ul> 382 383 <li>The material theme</li> 384 <li>View shadows</li> 385 <li>The {@link android.support.v7.widget.RecyclerView} widget</li> 386 <li>Drawable animation and styling effects</li> 387 <li>Material design animation and activity transition effects</li> 388 <li>Animators for view properties based on the state of the view</li> 389 <li>Customizable UI widgets and app bars with color palettes that you control</li> 390 <li>Animated and non-animated drawables based on XML vector graphics</li> 391</ul> 392 393<p>To learn more about adding material design functionality to your app, see 394<a href="{@docRoot}training/material/index.html">Material Design</a>.</p> 395 396<h3 id="Recents">Concurrent documents and activities in the recents screen</h3> 397 398<p>In previous releases, the 399<a href="{@docRoot}guide/components/recents.html">recents screen</a> 400could only display only one task for each app that the user interacted with 401most recently. Now your app can open more tasks as needed for additional 402concurrent activities for documents. This feature facilitates multitasking by 403letting users quickly switch between individual activities and documents from 404the recents screen, with a consistent switching experience across all apps. 405Examples of such concurrent tasks might include open tabs in a web 406browser app, documents in a productivity app, concurrent matches in 407a game, or chats in a messaging app. Your app can manage its tasks 408through the {@link android.app.ActivityManager.AppTask} class.</p> 409 410<p>To insert a logical break so that the system treats your activity as a new 411task, use {@link android.content.Intent#FLAG_ACTIVITY_NEW_DOCUMENT} when 412launching the activity with {@link android.app.Activity#startActivity(android.content.Intent) 413startActivity()}. You can also get this behavior by setting the 414<a href="{@docRoot}guide/topics/manifest/activity-element.html"><activity></a> 415element's {@code documentLaunchMode} attribute to {@code "intoExisting"} or 416{@code "always"} in your manifest.</p> 417 418<p>To avoid cluttering the recents screen, you can set the maximum number of 419tasks from your app that can appear in that screen. To do this, set the 420<a href="{@docRoot}guide/topics/manifest/application-element.html"><application></a> 421attribute {@link android.R.attr#maxRecents android:maxRecents}. The current 422maximum that can be specified is 50 tasks per user (25 for low RAM devices).</a></p> 423 424<p>Tasks in the recents screen can be set to persist across reboots. To control 425the persistence behavior, use the 426<a href="{@docRoot}reference/android/R.attr.html#persistableMode">android:persistableMode</a> 427attribute. You can also change 428the visual properties of an activity in the recents screen, such as the 429activity’s color, label, and icon. To do this, make sure the 430<a href="{@docRoot}reference/android/R.attr.html#relinquishTaskIdentity">android:relinquishTaskIdentity</a> 431attribute of the task’s root activity is set 432to {@code true}. You can then use the 433{@link android.app.Activity#setTaskDescription(android.app.ActivityManager.TaskDescription) setTaskDescription()} 434method to set its appearance properties.</p> 435 436<h3 id="WebView">WebView updates</h3> 437<p>Android 5.0 updates the {@link android.webkit.WebView} 438implementation to Chromium M37, bringing security and stability enhancements, 439as well as bug fixes. The default user-agent string for a 440{@link android.webkit.WebView} running on Android 5.0 has 441been updated to incorporate 37.0.0.0 as the version number.</p> 442 443<p>This release introduces the {@link android.webkit.PermissionRequest} class, 444which allows your app to grant the {@link android.webkit.WebView} permission 445to access protected resources like the camera and microphone, through web APIs 446such as <a href="https://developer.mozilla.org/en-US/docs/NavigatorUserMedia.getUserMedia" 447class="external-link">getUserMedia()</a>. Your app must have the appropriate 448Android permissions for these resources in order to grant the permissions to the 449{@link android.webkit.WebView}.</p> 450 451<p>With the new <code><a href="{@docRoot}reference/android/webkit/WebChromeClient.html#onShowFileChooser(android.webkit.WebView, android.webkit.ValueCallback<android.net.Uri[]>, android.webkit.WebChromeClient.FileChooserParams)">onShowFileChooser()</a></code> method, 452you can now use an input form field in the {@link android.webkit.WebView}, 453and launch a file chooser to select images and files from the Android device.</p> 454 455<p>Additionally, this release brings support for the 456<a href="http://webaudio.github.io/web-audio-api/" class="external-link">WebAudio</a>, 457<a href="https://www.khronos.org/webgl/" class="external-link">WebGL</a>, and 458<a href="http://www.webrtc.org/" class="external-link">WebRTC</a> open standards. 459To learn more about the new features included in this release, see 460<a href="https://developer.chrome.com/multidevice/webview/overview" 461class="external-link">WebView for Android</a>.</p> 462 463<h3 id="ScreenCapture">Screen capturing and sharing</h3> 464<p>Android 5.0 lets you add screen capturing and screen sharing capabilities to 465your app with the new {@link android.media.projection} APIs. This functionality 466is useful, for example, if you want to enable screen sharing in a video 467conferencing app.</p> 468 469<p>The new {@link android.media.projection.MediaProjection#createVirtualDisplay(java.lang.String, int, int, int, int, android.view.Surface, android.hardware.display.VirtualDisplay.Callback, android.os.Handler) createVirtualDisplay()} method 470allows your app to capture the contents of the main screen (the default 471display) into a {@link android.view.Surface} object, which your app can then 472send across the network. The API only allows capturing non-secure screen 473content, and not system audio. To begin screen capturing, your app must first 474request the user’s permission by launching a screen capture dialog using an 475{@link android.content.Intent} obtained through the 476{@link android.media.projection.MediaProjectionManager#createScreenCaptureIntent()} 477method.</p> 478 479<p>For an example of how to use the new APIs, see the {@code MediaProjectionDemo} 480class in the {@code ApiDemos} sample project.</p> 481 482<h2 id="Notifications">Notifications</h2> 483 484<h3 id="LockscreenNotifications">Lock screen notifications</h3> 485<p>Lock screens in Android 5.0 have the ability to present 486notifications. Users can choose via <em>Settings</em> whether to allow 487sensitive notification content to be shown over a secure lock screen.</p> 488 489<p>Your app can control the level of detail visible when its notifications are 490displayed over the secure lock screen. To control the visibility level, call 491{@link android.app.Notification.Builder#setVisibility(int) setVisibility()} and 492specify one of these values:</p> 493 494<ul> 495<li>{@link android.app.Notification#VISIBILITY_PRIVATE VISIBILITY_PRIVATE}: 496Shows basic information, such as the notification’s icon, but hides the 497notification’s full content.</li> 498<li>{@link android.app.Notification#VISIBILITY_PUBLIC VISIBILITY_PUBLIC}: 499Shows the notification’s full content.</li> 500<li>{@link android.app.Notification#VISIBILITY_SECRET VISIBILITY_SECRET}: 501Shows nothing, excluding even the notification’s icon.</li> 502</ul> 503 504<p>When the visibility level is {@link android.app.Notification#VISIBILITY_PRIVATE VISIBILITY_PRIVATE}, 505 you can also provide a redacted version of the notification 506content that hides personal details. For example, an SMS app might display a 507notification that shows "You have 3 new text messages" but hides the message 508content and senders. To provide this alternative notification, first create the 509replacement notification using {@link android.app.Notification.Builder}. When 510you create the private notification object, attach the replacement notification 511to it through the 512{@link android.app.Notification.Builder#setPublicVersion(android.app.Notification) 513 setPublicVersion()} method.</p> 514 515<h3 id="NotificationsMetadata">Notifications metadata</h3> 516<p>Android 5.0 uses metadata associated with your app notifications 517to sort the notifications more intelligently. To set the metadata, call the 518following methods in {@link android.app.Notification.Builder} when you 519construct the notification:</p> 520 521<ul> 522<li>{@link android.app.Notification.Builder#setCategory(java.lang.String) 523 setCategory()}: Tells the system how to handle your app notifications when the 524 device is in <em>priority</em> mode (for example, if a notification represents an 525incoming call, instant message, or alarm). 526<li>{@link android.app.Notification.Builder#setPriority(int) setPriority()}: 527 Marks the notification as more or less important than normal notifications. 528 Notifications with the priority field set to 529 {@link android.app.Notification#PRIORITY_MAX PRIORITY_MAX} or 530{@link android.app.Notification#PRIORITY_HIGH PRIORITY_HIGH} appear in a 531small floating window if the notification also has sound or vibration.</li> 532<li>{@link android.app.Notification.Builder#addPerson(java.lang.String) 533addPerson()}: Enables you to add one or more people who are relevant to a notification. 534Your app can use this to signal to the system that it should group together 535notifications from the specified people, or rank notifications from these people 536as being more important.</li> 537</ul> 538 539<h2 id="Graphics">Graphics</h2> 540 541<h3 id="OpenGLES-3-1">Support for OpenGL ES 3.1</h3> 542<p>Android 5.0 adds Java interfaces and native support for OpenGL 543ES 3.1. Key new functionality provided in OpenGL ES 3.1 includes:</p> 544 545<ul> 546<li>Compute shaders 547<li>Separate shader objects 548<li>Indirect draw commands 549<li>Multisample and stencil textures 550<li>Shading language improvements 551<li>Extensions for advanced blend modes and debugging 552<li>Backward compatibility with OpenGL ES 2.0 and 3.0 553</ul> 554 555<p>The Java interface for OpenGL ES 3.1 on Android is provided with 556 {@link android.opengl.GLES31}. When using OpenGL ES 3.1, be sure that you 557 declare it in your manifest file with the 558 <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html">{@code <uses-feature>}</a> tag and the {@code android:glEsVersion} attribute. For example:</p> 559 560<pre> 561<manifest> 562 <uses-feature android:glEsVersion="0x00030001" /> 563 ... 564</manifest> 565</pre> 566 567<p>For more information about using OpenGL ES, including how to check the 568device’s supported OpenGL ES version at runtime, see the 569<a href="{@docRoot}guide/topics/graphics/opengl.html">OpenGL ES API guide</a>.</p> 570 571<h3 id="AndroidExtensionPack">Android Extension Pack</h3> 572 573<p>In addition to OpenGL ES 3.1, this release provides an extension pack with 574Java interfaces and native support for advanced graphics functionality. These 575extensions are treated as a single package by Android. (If the 576{@code ANDROID_extension_pack_es31a} extension is present, your app can 577assume all extensions in the package are present and enable the shading language 578features with a single {@code #extension} statement.)</p> 579 580<p>The extension pack supports:</p> 581 582<ul> 583<li>Guaranteed fragment shader support for shader storage buffers, images, and 584 atomics (Fragment shader support is optional in OpenGL ES 3.1.)</li> 585<li>Tessellation and geometry shaders</li> 586<li>ASTC (LDR) texture compression format</li> 587<li>Per-sample interpolation and shading</li> 588<li>Different blend modes for each color attachment in a frame buffer</li> 589</ul> 590 591<p>The Java interface for the extension pack is provided with 592 {@link android.opengl.GLES31Ext}. In your app manifest, you can declare that 593 your app must be installed only on devices that support the extension pack. 594 For example:</p> 595 596<pre> 597<manifest> 598 <uses-feature android:name=“android.hardware.opengles.aep” 599 android:required="true" /> 600 ... 601</manifest> 602</pre> 603 604<h2 id="Media">Media</h2> 605 606<h3 id="Camera-v2">Camera API for advanced camera capabilities</h3> 607 608<p>Android 5.0 introduces the new 609<a href="{@docRoot}reference/android/hardware/camera2/package-summary.html">android.hardware.camera2</a> 610API to facilitate fine-grain photo capture and image processing. You can now 611programmatically access the camera devices available to the system with 612{@link android.hardware.camera2.CameraManager#getCameraIdList() getCameraIdList()} 613and connect to a specific device with 614{@link android.hardware.camera2.CameraManager#openCamera(java.lang.String, android.hardware.camera2.CameraDevice.StateCallback, android.os.Handler) openCamera()}. 615To start capturing images, create a {@link android.hardware.camera2.CameraCaptureSession} 616and specify the {@link android.view.Surface} objects to send captured images. 617The {@link android.hardware.camera2.CameraCaptureSession} can be configured to 618take single shots or multiple images in a burst.</p> 619 620<p>To be notified when new images are captured, implement the 621{@link android.hardware.camera2.CameraCaptureSession.CaptureCallback} listener 622and set it in your capture request. Now when the system completes the image 623capture request, your {@link android.hardware.camera2.CameraCaptureSession.CaptureCallback} 624listener receives a call to 625{@link android.hardware.camera2.CameraCaptureSession.CaptureCallback#onCaptureCompleted(android.hardware.camera2.CameraCaptureSession, android.hardware.camera2.CaptureRequest, android.hardware.camera2.TotalCaptureResult) onCaptureCompleted()}, 626providing you with the image capture metadata in a 627{@link android.hardware.camera2.CaptureResult}.</p> 628 629<p>The {@link android.hardware.camera2.CameraCharacteristics} class lets your 630app detect what camera features are available on a device. The object's 631{@link android.hardware.camera2.CameraCharacteristics#INFO_SUPPORTED_HARDWARE_LEVEL 632INFO_SUPPORTED_HARDWARE_LEVEL} property represents the camera's level of functionality.</p> 633 634<ul> 635 <li>All devices support at least the 636{@link android.hardware.camera2.CameraMetadata#INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY 637 INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY} hardware level, which has capabilities 638 roughly equivalent to that of the deprecated {@link android.hardware.Camera} 639 API.</li> 640 <li>Devices that support the {@link android.hardware.camera2.CameraMetadata#INFO_SUPPORTED_HARDWARE_LEVEL_FULL 641 INFO_SUPPORTED_HARDWARE_LEVEL_FULL} hardware level are capable of manual 642 control of capture and post-processing, and capturing high-resolution images 643 at high frame rates.</li> 644</ul> 645 646<p>To see how to use the updated 647<a href="{@docRoot}reference/android/hardware/camera2/package-summary.html">Camera</a> 648API, refer to the {@code Camera2Basic} and {@code Camera2Video} implementation 649samples in this release.</p> 650 651<h3 id="AudioPlayback">Audio playback</h3> 652<p>This release includes the following changes to 653 {@link android.media.AudioTrack}:</p> 654<ul> 655 <li>Your app can now supply audio data in floating-point format 656({@link android.media.AudioFormat#ENCODING_PCM_FLOAT ENCODING_PCM_FLOAT}). This 657permits greater dynamic range, more consistent precision, and greater headroom. 658Floating-point arithmetic is especially useful during intermediate calculations. 659Playback endpoints use integer format for audio data, and with lower bit depth. 660(In Android 5.0, portions of the internal pipeline are not yet 661floating point.) 662 <li>Your app can now supply audio data as a {@link java.nio.ByteBuffer}, in 663the same format as provided by {@link android.media.MediaCodec}. 664 <li>The {@link android.media.AudioTrack#WRITE_NON_BLOCKING WRITE_NON_BLOCKING} 665option can simplify buffering and multithreading for some apps. 666</ul> 667 668<h3 id="MediaPlaybackControl">Media playback control</h3> 669<p>Use the new notification and media APIs to ensure that the 670system UI knows about your media playback and can extract and show album art. 671Controlling media playback across a UI and a service is now easier with the new 672{@link android.media.session.MediaSession} and 673{@link android.media.session.MediaController} classes.</p> 674 675<p>The new {@link android.media.session.MediaSession} class replaces 676the deprecated {@link android.media.RemoteControlClient} class and provides a 677single set of callback methods for handling transport controls and media buttons. 678If your app provides media playback and runs on the Android 679<a href="{@docRoot}tv/index.html">TV</a> or 680<a href="{@docRoot}wear/index.html">Wear</a> platform, use the 681{@link android.media.session.MediaSession} class to handle your transport 682controls using the same callback methods.</p> 683 684<p>You can now build your own media controller app with the new 685{@link android.media.session.MediaController} class. This class provides 686a thread-safe way to monitor and control media playback from your app's UI process. 687When creating a controller, specify a {@link android.media.session.MediaSession.Token} 688object so that your app can interact with the given {@link android.media.session.MediaSession}. 689By using the {@link android.media.session.MediaController.TransportControls} methods, 690you can send commands such as {@link android.media.session.MediaController.TransportControls#play() play()}, 691{@link android.media.session.MediaController.TransportControls#stop() stop()}, 692{@link android.media.session.MediaController.TransportControls#skipToNext() skipToNext()}, 693and {@link android.media.session.MediaController.TransportControls#setRating(android.media.Rating) setRating()} 694to control media playback on that session. With the controller, you can also 695register a {@link android.media.session.MediaController.Callback} object to 696listen for metadata and state changes on the session.</p> 697 698<p>In addition, you can create rich notifications that allow playback control 699tied to a media session with the new {@link android.app.Notification.MediaStyle} 700class.</p> 701 702<h3 id="MediaBrowsing">Media browsing</h3> 703<p>Android 5.0 introduces the ability for apps to browse the media content 704 library of another app, through the new 705 <a href="{@docRoot}reference/android/media/browse/package-summary.html">android.media.browse</a> 706 API. To expose the media content in your app, extend the 707{@link android.service.media.MediaBrowserService} class. Your implementation of 708{@link android.service.media.MediaBrowserService} should provide access to a 709{@link android.media.session.MediaSession.Token} so that apps can play media content 710provided through your service.</p> 711<p>To interact with a media browser service, use the 712 {@link android.media.browse.MediaBrowser} class. Specify the component 713 name for a {@link android.media.session.MediaSession} when you create an 714 {@link android.media.browse.MediaBrowser} instance. Using that browser instance, 715 your app can then connect to the associated service and obtain a 716 {@link android.media.session.MediaSession.Token} object to play content exposed 717 through that service.</p> 718 719<h2 id="Storage">Storage</h2> 720 721<h3 id="DirectorySelection">Directory selection</h3> 722 723<p>Android 5.0 extends the 724 <a href="{@docRoot}guide/topics/providers/document-provider.html">Storage Access Framework</a> 725to let users select an entire directory subtree, giving apps read/write access 726to all contained documents without requiring user confirmation for each item.</p> 727 728<p>To select a directory subtree, build and send an 729{@link android.content.Intent#ACTION_OPEN_DOCUMENT_TREE OPEN_DOCUMENT_TREE} 730intent. The system displays all 731{@link android.provider.DocumentsProvider} instances that support subtree selection, 732letting the user browse and select a directory. The returned URI represents 733access to the selected subtree. You can then use {@link 734android.provider.DocumentsContract#buildChildDocumentsUriUsingTree(android.net.Uri, java.lang.String) buildChildDocumentsUriUsingTree()} 735and {@link android.provider.DocumentsContract#buildDocumentUriUsingTree(android.net.Uri, java.lang.String) buildDocumentUriUsingTree()} 736along with 737{@link android.content.ContentResolver#query(android.net.Uri, java.lang.String[], java.lang.String, java.lang.String[], java.lang.String) query()} 738to explore the subtree.</p> 739 740<p>The new {@link android.provider.DocumentsContract#createDocument(android.content.ContentResolver, android.net.Uri, java.lang.String, java.lang.String) 741createDocument()} method lets you create new documents or directories anywhere 742under the subtree. To manage existing documents, use 743{@link android.provider.DocumentsContract#renameDocument(android.content.ContentResolver, android.net.Uri, java.lang.String) renameDocument()} and 744{@link android.provider.DocumentsProvider#deleteDocument(java.lang.String) deleteDocument()}. 745Check {@link android.provider.DocumentsContract.Document#COLUMN_FLAGS COLUMN_FLAGS} 746to verify provider support for these calls before issuing them.</p> 747 748<p>If you're implementing a {@link android.provider.DocumentsProvider} and want 749to support subtree selection, implement {@link android.provider.DocumentsProvider#isChildDocument(java.lang.String, java.lang.String) isChildDocument()} and include {@link 750android.provider.DocumentsContract.Root#FLAG_SUPPORTS_IS_CHILD FLAG_SUPPORTS_IS_CHILD} 751in your {@link android.provider.DocumentsContract.Root#COLUMN_FLAGS COLUMN_FLAGS}.</p> 752 753<p>Android 5.0 also introduces new package-specific directories on 754shared storage where your app can place media files for inclusion in 755{@link android.provider.MediaStore}. The new 756{@link android.content.Context#getExternalMediaDirs()} returns paths to these 757directories on all shared storage devices. Similarly to 758{@link android.content.Context#getExternalFilesDir(java.lang.String) getExternalFilesDir()}, 759no additional permissions are needed by your app to access the returned paths. The 760platform periodically scans for new media in these directories, but you can also 761use {@link android.media.MediaScannerConnection} to explicitly scan for new 762content.</p> 763 764<h2 id="Wireless">Wireless & Connectivity</h2> 765 766<h3 id="Multinetwork">Multiple network connections</h3> 767<p>Android 5.0 provides new multi-networking APIs that let your app 768dynamically scan for available networks with specific capabilities, and 769establish a connection to them. This functionality is useful when your app 770requires a specialized network, such as an SUPL, MMS, or carrier-billing network, 771or if you want to send data using a particular type of transport protocol.</p> 772 773<p>To select and connect to a network dynamically from your app, follow these 774steps:</p> 775 776<ol> 777 <li>Create a {@link android.net.ConnectivityManager}.</li> 778 <li>Use the {@link android.net.NetworkRequest.Builder} class to create an 779 {@link android.net.NetworkRequest} object and specify the network features 780 and transport type your app is interested in.</li> 781<li>To scan for suitable networks, call {@link android.net.ConnectivityManager#requestNetwork(android.net.NetworkRequest, android.net.ConnectivityManager.NetworkCallback) requestNetwork()} 782or {@link android.net.ConnectivityManager#registerNetworkCallback(android.net.NetworkRequest, android.net.ConnectivityManager.NetworkCallback) registerNetworkCallback()}, and pass in the 783{@link android.net.NetworkRequest} object and an implementation of 784{@link android.net.ConnectivityManager.NetworkCallback}. Use the 785{@link android.net.ConnectivityManager#requestNetwork(android.net.NetworkRequest, android.net.ConnectivityManager.NetworkCallback) requestNetwork()} method if you want to actively switch to a suitable network once it’s detected; to receive 786only notifications for scanned networks without actively switching, use the 787{@link android.net.ConnectivityManager#registerNetworkCallback(android.net.NetworkRequest, android.net.ConnectivityManager.NetworkCallback) registerNetworkCallback()} method instead.</li> 788</ol> 789 790<p>When the system detects a suitable network, it connects to the network and 791invokes the 792{@link android.net.ConnectivityManager.NetworkCallback#onAvailable(android.net.Network) onAvailable()} 793callback. You can use the {@link android.net.Network} object from the callback to 794get additional information about the network, or to direct traffic to use the 795selected network.</p> 796 797<h3 id="BluetoothBroadcasting">Bluetooth Low Energy</h3> 798<p>Android 4.3 introduced platform support for 799 <a href="{@docRoot}guide/topics/connectivity/bluetooth-le.html">Bluetooth Low Energy</a> 800(<em>Bluetooth LE</em>) in the central role. In Android 5.0, an Android device can now 801act as a Bluetooth LE <em>peripheral device</em>. Apps can use this capability 802to make their presence known to nearby devices. For instance, you can build apps 803that allow a device to function as a pedometer or health monitor and communicate 804its data with another Bluetooth LE device.</p> 805 806<p>The new {@link android.bluetooth.le} APIs enable your apps to broadcast 807advertisements, scan for responses, and form connections with nearby Bluetooth 808LE devices. To use the new advertising and scanning features, add the 809{@link android.Manifest.permission#BLUETOOTH_ADMIN BLUETOOTH_ADMIN} 810permission in your manifest. When users update or download your app from the Play Store, 811they are asked to grant the following permission to your app: 812"Bluetooth connection information: Allows the app to control Bluetooth, 813including broadcasting to or getting information about nearby Bluetooth devices."</p> 814 815<p>To begin Bluetooth LE advertising so that other devices can discover 816your app, call 817{@link android.bluetooth.le.BluetoothLeAdvertiser#startAdvertising(android.bluetooth.le.AdvertiseSettings, android.bluetooth.le.AdvertiseData, android.bluetooth.le.AdvertiseCallback) startAdvertising()} 818and pass in an implementation of the 819{@link android.bluetooth.le.AdvertiseCallback} class. The callback object 820receives a report of the success or failure of the advertising operation.</p> 821 822<p> Android 5.0 introduces the {@link android.bluetooth.le.ScanFilter} class so 823 that your app can scan for only the 824specific types of devices it is interested in. To begin scanning for Bluetooth 825LE devices, call {@link android.bluetooth.le.BluetoothLeScanner#startScan(android.bluetooth.le.ScanCallback) startScan()} 826and pass in a list of filters. In the method call, you must also provide an 827implementation of {@link android.bluetooth.le.ScanCallback} to report when a 828Bluetooth LE advertisement is found. </p> 829 830<h3 id="NFCEnhancements">NFC enhancements</h3> 831<p>Android 5.0 adds these enhancements to enable wider and more 832flexible use of NFC:</p> 833 834<ul> 835<li>Android Beam is now available in the <em>share</em> menu.</li> 836<li>Your app can invoke the Android Beam on the user’s device to share data by 837calling {@link android.nfc.NfcAdapter#invokeBeam(android.app.Activity) invokeBeam()}. 838This avoids the need for the user to manually tap the device against another 839NFC-capable device to complete the data transfer.</li> 840<li>You can use the new {@link android.nfc.NdefRecord#createTextRecord(java.lang.String, java.lang.String) 841 createTextRecord()} method to create an NDEF record containing UTF-8 text data.</li> 842<li>If you are developing a payment app, you now have the ability to 843register an NFC application ID (AID) dynamically by calling 844<code><a href="{@docRoot}reference/android/nfc/cardemulation/CardEmulation.html#registerAidsForService(android.content.ComponentName, java.lang.String, java.util.List<java.lang.String>)">registerAidsForService()</a></code>. 845You can also use {@link android.nfc.cardemulation.CardEmulation#setPreferredService(android.app.Activity, android.content.ComponentName) setPreferredService()} to set the preferred card emulation service that should 846be used when a specific activity is in the foreground.</li> 847</ul> 848 849<h2 id="Power">Project Volta</h2> 850 851<p>In addition to new features, Android 5.0 emphasizes improvements in battery 852 life. Use the new APIs and tool to understand and optimize your app’s power 853 consumption.</p> 854 855<h3 id="JobScheduler">Scheduling jobs</h3> 856<p>Android 5.0 provides a new {@link android.app.job.JobScheduler} 857API that lets you optimize battery life by defining jobs for the system to run 858asynchronously at a later time or under specified conditions (such as when the 859device is charging). Job scheduling is useful in such situations as:</p> 860<ul> 861 <li>The app has non-user-facing work that you can defer.</li> 862 <li>The app has work you'd prefer to do when the unit is plugged in.</li> 863 <li>The app has a task that requires network access or a Wi-Fi 864 connection.</li> 865 <li>The app has a number of tasks that you want to run as a batch on a regular 866 schedule.</li> 867 868</ul> 869 870<p>A unit of work is encapsulated by a {@link android.app.job.JobInfo} object. 871This object specifies the scheduling criteria.</p> 872 873<p>Use the {@link android.app.job.JobInfo.Builder} class to configure how the 874scheduled task should run. You can schedule the task to run under specific 875conditions, such as:</p> 876 877<ul> 878 <li>Start when the device is charging</li> 879 <li>Start when the device is connected to an unmetered network</li> 880 <li>Start when the device is idle</li> 881 <li>Finish before a certain deadline or with a minimum delay</li> 882</ul> 883 884<p>For example, you can add code like this to run your task on an 885unmetered network:</p> 886 887<pre> 888JobInfo uploadTask = new JobInfo.Builder(mJobId, 889 mServiceComponent /* JobService component */) 890 .setRequiredNetworkCapabilities(JobInfo.NetworkType.UNMETERED) 891 .build(); 892JobScheduler jobScheduler = 893 (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE); 894jobScheduler.schedule(uploadTask); 895</pre> 896 897<p>If the device has stable power (that is, it has been plugged in for more 898 than 2 minutes and the battery is at a 899<a href="{@docRoot}reference/android/content/Intent.html#ACTION_BATTERY_OKAY">healthy level</a>), 900the system will run any scheduled job that is ready to run, even if the job’s 901deadline has not expired.</p> 902 903<p>To see an example of how to use the {@link android.app.job.JobScheduler} API, 904refer to the {@code JobSchedulerSample} implementation sample in this release.</p> 905 906<h3 id="PowerMeasurementTools">Developer tools for battery usage</h3> 907 908<p>The new {@code dumpsys batterystats} command generates interesting 909statistical data about battery usage on a device, organized by unique user ID 910(UID). The statistics include:</p> 911 912<ul> 913<li>History of battery related events 914<li>Global statistics for the device 915<li>Approximate power use per UID and system component 916<li>Per-app mobile ms per packet 917<li>System UID aggregated statistics 918<li>App UID aggregated statistics 919</ul> 920 921<p>Use the {@code --help} option to learn about the various options for 922tailoring the output. For example, to print battery usage 923statistics for a given app package since the device was last charged, run this 924command: 925<pre> 926$ adb shell dumpsys batterystats --charged <package-name> 927</pre> 928 929<p>You can use the 930 <a href="https://github.com/google/battery-historian" class="external-link">Battery Historian</a> 931 tool on the output of the {@code dumpsys} command to 932generate an HTML visualization of power-related events from the logs. This 933information makes it easier for you to understand and diagnose any battery 934related issues.</p> 935 936<h2 id="Enterprise">Android in the Workplace and in Education</h2> 937<h3 id="ManagedProvisioning">Managed provisioning</h3> 938 939<div class="figure" style="width:360px"> 940 <img src="../../images/android-5.0/managed_apps_launcher.png" 941 srcset="../../images/android-5.0/managed_apps_launcher@2x.png 2x" 942 alt="" width="360" height="609" id="figure3" /> 943 <p class="img-caption"> 944 <strong>Figure 2.</strong> Launcher screen showing managed apps (marked with 945 a lock badge) 946 </p> 947</div> 948 949<p>Android 5.0 provides new functionality for running apps within 950an enterprise environment. A 951<a href="{@docRoot}guide/topics/admin/device-admin.html">device administrator</a> can 952initiate a managed provisioning process to add a copresent but separate 953<em>managed profile</em> to a device, if the user has an existing personal account. 954Apps that are associated with managed profiles appear alongside 955non-managed apps in the user’s Launcher, recents screen, and notifications.</p> 956 957<p>To start the managed provisioning process, send 958{@link android.app.admin.DevicePolicyManager#ACTION_PROVISION_MANAGED_PROFILE 959ACTION_PROVISION_MANAGED_PROFILE} in an {@link android.content.Intent}. If the 960call is successful, the system triggers the 961{@link android.app.admin.DeviceAdminReceiver#onProfileProvisioningComplete(android.content.Context, android.content.Intent) onProfileProvisioningComplete()} callback. 962You can then call {@link android.app.admin.DevicePolicyManager#setProfileEnabled(android.content.ComponentName) setProfileEnabled()} to 963enable this managed profile.</p> 964 965<p>By default, only a small subset of apps are enabled in the managed profile. 966 You can install additional apps in the managed profile by calling 967 {@link android.app.admin.DevicePolicyManager#enableSystemApp(android.content.ComponentName, android.content.Intent) enableSystemApp()}.</p> 968 969<p>If you are developing a Launcher app, you can use the new {@link 970android.content.pm.LauncherApps} class to get a list of launchable activities 971for the current user and any associated managed profiles. Your Launcher can make 972the managed apps visually prominent by appending a work badge to the icon 973drawable. To retrieve the badged icon, call 974{@link android.content.pm.PackageManager#getUserBadgedIcon(android.graphics.drawable.Drawable, android.os.UserHandle) 975getUserBadgedIcon()}.</p> 976 977<p>To see how to use the new functionality, refer to the 978{@code BasicManagedProfile} implementation sample in this release.</p> 979 980<h3 id="DeviceOwner">Device owner</h3> 981<p>Android 5.0 introduces the ability to deploy a device owner app. A <em>device 982 owner</em> is a specialized type of 983 <a href="{@docRoot}guide/topics/admin/device-admin.html">device administrator</a> 984 that has the additional ability to create and remove secondary users and to 985 configure global settings on the device. Your device owner app can use the 986 methods in the {@link android.app.admin.DevicePolicyManager} class to take 987 fine-grain control of the configuration, security, and apps on managed devices. 988 A device can have only one active device owner at a time.</p> 989 990<p>To deploy and activate a device owner, you must perform an NFC data transfer 991 from a programming app to the device while the device is in its unprovisioned 992 state. This data transfer sends the same information as in the provisioning intent 993 described in <a href="#ManagedProvisioning">Managed provisioning</a>.</p> 994 995<h3 id="ScreenPinning">Screen pinning</h3> 996 997<p>Android 5.0 introduces a new screen pinning API that lets you temporarily 998 restrict users from leaving your task or being interrupted by notifications. 999 This could be used, for example, if you are developing an education app to 1000 support high stakes assessment requirements on Android, or a single-purpose or 1001 kiosk application. Once your app activates screen pinning, users cannot see 1002 notifications, access other apps, or return to the home screen, 1003 until your app exits the mode.</p> 1004 1005<p>There are two ways to activate screen pinning:</p> 1006 1007<ul> 1008<li><strong>Manually:</strong> Users can enable screen pinning in 1009<em>Settings > Security > Screen Pinning</em>, and select the tasks they want to 1010pin by touching the green pin icon in the recents screen.</li> 1011<li><strong>Programmatically:</strong> To activate screen pinning 1012programmatically, call {@link android.app.Activity#startLockTask() startLockTask()} 1013from your app. If the requesting app is not a device owner, the user is prompted 1014for confirmation. A device owner app can call the 1015{@link android.app.admin.DevicePolicyManager#setLockTaskPackages(android.content.ComponentName, java.lang.String[]) setLockTaskPackages()} 1016method to enable apps to be pinnable without the user confirmation step.</li> 1017</ul> 1018 1019<p>When task locking is active, the following behavior happens:</p> 1020 1021<ul> 1022<li>The status bar is blank, and user notifications and status information are 1023hidden.</li> 1024<li>The Home and Recent Apps buttons are hidden.</li> 1025<li>Other apps cannot launch new activities.</li> 1026<li>The current app can start new activities, as long as doing so does not 1027create new tasks.</li> 1028<li>When screen pinning is invoked by a device owner, the user remains locked 1029 to your app until the app calls 1030 {@link android.app.Activity#stopLockTask() stopLockTask()}.</li> 1031<li>If screen pinning is activity by another app that is not a device owner or 1032by the user directly, the user can exit by holding both the Back and Recent buttons.</li> 1033 1034</ul> 1035 1036<h2 id="Printing">Printing Framework</h2> 1037 1038<h3 id="PDFRender">Render PDF as bitmap</h3> 1039<p>You can now render PDF document pages into bitmap images for printing by 1040using the new {@link android.graphics.pdf.PdfRenderer} class. You must specify a 1041{@link android.os.ParcelFileDescriptor} that is seekable (that is, the content 1042can be randomly accessed) on which the system writes the the printable content. 1043Your app can obtain a page for rendering with 1044{@link android.graphics.pdf.PdfRenderer#openPage(int) openPage()}, then call 1045{@link android.graphics.pdf.PdfRenderer.Page#render(android.graphics.Bitmap, android.graphics.Rect, android.graphics.Matrix, int) render()} 1046to turn the opened {@link android.graphics.pdf.PdfRenderer.Page} into a bitmap. You 1047can also set additional parameters if you only want to convert a portion of the 1048document into a bitmap image (for example, to implement 1049<a href="http://en.wikipedia.org/wiki/Tiled_rendering" class="external-link">tiled rendering</a> 1050to zoom in on the document).</p> 1051 1052<p>For an example of how to use the new APIs, see the {@code PdfRendererBasic} 1053 sample.</p> 1054 1055<h2 id="System">System</h2> 1056<h3 id="AppUsageStatistics">App usage statistics</h3> 1057<p>You can now access app usage history on an Android device with the 1058 new {@link android.app.usage} API. This API provides more detailed usage 1059 information than the deprecated 1060 {@link android.app.ActivityManager#getRecentTasks(int, int) getRecentTasks()} method. 1061 To use this API, you must first declare the 1062 {@code "android.permission.PACKAGE_USAGE_STATS"} permission in your manifest. 1063 The user must also enable access for this app through <em>Settings > Security > Apps</em> 1064 with usage access.</p> 1065 1066<p>The system collects the usage data on a per-app basis, aggregating the 1067 data over daily, weekly, monthly, and yearly intervals. The maximum duration 1068 that the system keeps this data is as follows:</p> 1069 1070<ul> 1071 <li>Daily data: 7 days</li> 1072 <li>Weekly data: 4 weeks</li> 1073 <li>Monthly data: 6 months</li> 1074 <li>Yearly data: 2 years</li> 1075</ul> 1076 1077<p>For each app, the system records the following data:</p> 1078<ul> 1079<li>The last time the app was used</li> 1080<li>The total length of time the app was in the foreground for that time interval 1081 (by day, week, month, or year)</li> 1082<li>Timestamp capturing when a component (identified by a package and activity name) 1083 moved to the foreground or background during a day</li> 1084<li>Timestamp capturing when a device configuration changed (such as when the 1085 device orientation changed because of rotation)</li> 1086</ul> 1087 1088<h2 id="TestingA11y">Testing & Accessibility </h2> 1089 1090<h3 id="TestingA11yImprovements">Testing and accessibility improvements</h3> 1091<p>Android 5.0 adds the following support for testing and 1092accessibility:</p> 1093 1094<ul> 1095<li>The new {@link android.app.UiAutomation#getWindowAnimationFrameStats() getWindowAnimationFrameStats()} 1096and {@link android.app.UiAutomation#getWindowContentFrameStats(int) getWindowContentFrameStats()} 1097methods capture frame statistics for window animations and content. These methods 1098let you write instrumentation tests to evaluate whether an app is rendering 1099frames at a sufficient refresh frequency to provide a smooth user experience.</li> 1100 1101<li>The new 1102{@link android.app.UiAutomation#executeShellCommand(java.lang.String) executeShellCommand()} 1103method lets you execute shell commands from your instrumentation test. The 1104command execution is similar to running {@code adb shell} from a host 1105connected to the device, allowing you to use shell-based tools such as 1106{@code dumpsys}, {@code am}, {@code content}, and {@code pm}.</li> 1107 1108<li>Accessibility services and test tools that use the accessibility APIs 1109(such as <a href="{@docRoot}tools/help/uiautomator/index.html">{@code UiAutomator}</a>) 1110can now retrieve detailed information about the properties of windows on the 1111screen that sighted users can interact with. To retrieve a list of 1112{@link android.view.accessibility.AccessibilityWindowInfo} objects, call the new 1113{@link android.accessibilityservice.AccessibilityService#getWindows() getWindows()} 1114method.</li> 1115 1116<li>The new {@link android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction} 1117 class lets you define standard or customized actions to perform on an 1118 {@link android.view.accessibility.AccessibilityNodeInfo}. 1119The new {@link android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction} 1120class replaces the actions-related APIs previously found in 1121{@link android.view.accessibility.AccessibilityNodeInfo}.</li> 1122 1123<li>Android 5.0 provides finer-grain control over text-to-speech synthesis in 1124 your app. The new {@link android.speech.tts.Voice} class allows your app to 1125 use voice profiles associated with specific locales, quality and latency 1126 rating, and text-to-speech engine-specific parameters.</li> 1127</ul> 1128 1129<h2 id="IME">IME</h2> 1130 1131<h3 id="Switching">Easier switching between input languages</h3> 1132 1133<p>Beginning in Android 5.0, users can more easily switch between 1134all <a href="{@docRoot}guide/topics/text/creating-input-method.html">input 1135method editors (IME)</a> supported by the platform. Performing the designated 1136switching action (usually touching a Globe icon on the soft keyboard) cycles 1137through all such IMEs. This change in behavior is implemented by the 1138{@link android.view.inputmethod.InputMethodManager#shouldOfferSwitchingToNextInputMethod(android.os.IBinder) shouldOfferSwitchingToNextInputMethod()} 1139method.</p> 1140 1141<p>In addition, the framework now checks whether the next IME includes a 1142switching mechanism at all (and, thus, whether that IME supports switching to 1143the IME after it). An 1144IME with a switching mechanism will not cycle to an IME without one. This 1145change in behavior is implemented by the 1146{@link android.view.inputmethod.InputMethodManager#switchToNextInputMethod(android.os.IBinder, boolean) switchToNextInputMethod()} 1147method. 1148 1149<p>To see an example of how to use the updated IME-switching APIs, refer to the 1150updated soft-keyboard implementation sample in this release. To learn more about 1151how to implement switching between IMEs, see 1152<a href="{@docRoot}guide/topics/text/creating-input-method.html">Creating an Input Method</a>. 1153</p> 1154 1155<h2 id="Manifest">Manifest Declarations</h2> 1156 1157<h3 id="ManifestFeatures">Declarable required features</h3> 1158<p>The following values are now supported in the 1159<a href="{@docRoot}guide/topics/manifest/uses-feature-element.html">{@code <uses-feature>}</a> 1160element, so you can ensure that your app is installed only on devices that 1161provide the features your app needs.</p> 1162 1163<ul> 1164<li>{@link android.content.pm.PackageManager#FEATURE_AUDIO_OUTPUT}</li> 1165<li>{@link android.content.pm.PackageManager#FEATURE_CAMERA_CAPABILITY_MANUAL_POST_PROCESSING}</li> 1166<li>{@link android.content.pm.PackageManager#FEATURE_CAMERA_CAPABILITY_MANUAL_SENSOR}</li> 1167<li>{@link android.content.pm.PackageManager#FEATURE_CAMERA_CAPABILITY_RAW}</li> 1168<li>{@link android.content.pm.PackageManager#FEATURE_CAMERA_LEVEL_FULL}</li> 1169<li>{@link android.content.pm.PackageManager#FEATURE_GAMEPAD}</li> 1170<li>{@link android.content.pm.PackageManager#FEATURE_LIVE_TV}</li> 1171<li>{@link android.content.pm.PackageManager#FEATURE_MANAGED_USERS}</li> 1172<li>{@link android.content.pm.PackageManager#FEATURE_LEANBACK}</li> 1173<li>{@link android.content.pm.PackageManager#FEATURE_OPENGLES_EXTENSION_PACK}</li> 1174<li>{@link android.content.pm.PackageManager#FEATURE_SECURELY_REMOVES_USERS}</li> 1175<li>{@link android.content.pm.PackageManager#FEATURE_SENSOR_AMBIENT_TEMPERATURE}</li> 1176<li>{@link android.content.pm.PackageManager#FEATURE_SENSOR_HEART_RATE_ECG}</li> 1177<li>{@link android.content.pm.PackageManager#FEATURE_SENSOR_RELATIVE_HUMIDITY}</li> 1178<li>{@link android.content.pm.PackageManager#FEATURE_VERIFIED_BOOT}</li> 1179<li>{@link android.content.pm.PackageManager#FEATURE_WEBVIEW}</li> 1180</ul> 1181 1182<h3 id="Permissions">User permissions</h3> 1183 1184<p>The following permission is now supported in the 1185<a href="{@docRoot}guide/topics/manifest/uses-permission-element.html">{@code <uses-permission>}</a> 1186element to declare the permissions your app requires to access certain APIs.</p> 1187 1188<ul> 1189<li>{@link android.Manifest.permission#BIND_DREAM_SERVICE}: When targeting API 1190 level 21 and higher, this permission is required by a 1191 <a href="{@docRoot}about/versions/android-4.2.html#Daydream">Daydream</a> service, 1192 to ensure that only the system can bind to it.</li> 1193</ul>