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