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