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