Robert Ly | 2055529 | 2014-06-13 23:28:19 -0700 | [diff] [blame] | 1 | page.title=L Developer Preview APIs |
| 2 | excludeFromSuggestions=true |
| 3 | sdk.platform.apiLevel=20 |
| 4 | @jd:body |
| 5 | |
| 6 | |
| 7 | <div id="qv-wrapper"> |
| 8 | <div id="qv"> |
| 9 | |
| 10 | <h2>In this document |
| 11 | <a href="#" onclick="hideNestedItems('#toc44',this);return false;" class="header-toggle"> |
| 12 | <span class="more">show more</span> |
| 13 | <span class="less" style="display:none">show less</span></a></h2> |
| 14 | |
| 15 | <ol id="toc44" class="hide-nested"> |
| 16 | <li><a href="#Behaviors">Important Behavior Changes</a> |
| 17 | <ol> |
| 18 | <li><a href="#BehaviorNotifications">If your app implements notifications...</a></li> |
| 19 | <li><a href="#BehaviorFullscreen">If your app uses fullScreenIntent...</a></li> |
| 20 | <li><a href="#BehaviorGetRecentTasks">If your app uses ActivityManager.getRecentTasks()...</a></li> |
| 21 | </ol> |
| 22 | </li> |
| 23 | <li><a href="#UI">User Interface</a> |
| 24 | <ol> |
| 25 | <li><a href="#MaterialDesign">Material design support</a></li> |
| 26 | <li><a href="#LockscreenNotifications">Lockscreen notifications</a></li> |
| 27 | <li><a href="#NotificationsMetadata">Notifications metadata</a></li> |
| 28 | <li><a href="#Recents">Concurrent documents and activities in Recents screen</a></li> |
| 29 | <li><a href="#WebView">WebView updates</a></li> |
| 30 | </ol> |
| 31 | </li> |
| 32 | <li><a href="#UserInput">User Input</a> |
| 33 | <ol> |
| 34 | <li><a href="#IME">IME bug fixes and improvements</a></li> |
| 35 | </ol> |
| 36 | </li> |
| 37 | <li><a href="#Animations">Animation & Graphics</a> |
| 38 | <ol> |
| 39 | <li><a href="#OpenGLES-3-1">Support for OpenGL ES 3.1</a></li> |
| 40 | </ol> |
| 41 | </li> |
| 42 | <li><a href="#Multimedia">Multimedia</a> |
| 43 | <ol> |
| 44 | <li><a href="#Camera-v2">Camera V2</a></li> |
| 45 | <li><a href="#AudioPlayback">Audio playback</a></li> |
| 46 | <li><a href="#MediaPlaybackControl">Media playback control</a></li> |
| 47 | </ol> |
| 48 | </li> |
| 49 | <li><a href="#Storage">Storage</a> |
| 50 | <ol> |
| 51 | <li><a href="#DirectorySelection">Directory selection</a></li> |
| 52 | </ol> |
| 53 | </li> |
| 54 | <li><a href="#Wireless">Wireless and Connectivity</a> |
| 55 | <ol> |
| 56 | <li><a href="#Multinetwork">Dynamic network selection and seamless handoff</a></li> |
| 57 | <li><a href="#BluetoothBroadcasting">Bluetooth broadcasting</a></li> |
| 58 | <li><a href="#NFCEnhancements">NFC enhancements for payments</a></li> |
| 59 | </ol> |
| 60 | </li> |
| 61 | <li><a href="#Power">Power Efficiency</a> |
| 62 | <ol> |
| 63 | <li><a href="#JobScheduler">Scheduling Jobs</a></li> |
| 64 | <li><a href="#PowerMeasurementTools">Developer tools and APIs for power measurement</a> |
| 65 | </ol> |
| 66 | </li> |
| 67 | <li><a href="#Enterprise">Enterprise</a> |
| 68 | <ol> |
| 69 | <li><a href="#ManagedProvisioning">Managed provisioning</a></li> |
| 70 | </ol> |
| 71 | </li> |
| 72 | <li><a href="#Printing">Printing Framework</a> |
| 73 | <ol> |
| 74 | <li><a href="#PDFRender">PDF rendering</a></li> |
| 75 | </ol> |
| 76 | </li> |
| 77 | <li><a href="#TestingA11y">Testing & Accessibility</a> |
| 78 | <ol> |
| 79 | <li><a href="#TestingA11yImprovements">Testing and accessibility improvements</a></li> |
| 80 | </ol> |
| 81 | </li> |
| 82 | <li><a href="#Manifest">Manifest Declarations</a> |
| 83 | <ol> |
| 84 | <li><a href="#ManifestFeatures">Declarable required features</a></li> |
| 85 | <li><a href="#ManifestPermissions">User permissions</a></li> |
| 86 | </ol> |
| 87 | </li> |
| 88 | </ol> |
| 89 | |
| 90 | <h2>See also</h2> |
| 91 | <ol> |
| 92 | <li><a href="{@docRoot}sdk/api_diff/20/changes.html">API |
| 93 | Differences Report »</a> </li> |
| 94 | </ol> |
| 95 | |
| 96 | </div> |
| 97 | </div> |
| 98 | |
| 99 | <p>L is an upcoming release for the Android platform |
| 100 | that offers new features for users and app developers. This document provides |
| 101 | an introduction to the most notable new APIs.</p> |
| 102 | |
| 103 | <p>L is currently available as a <strong>developer preview</strong> intended |
| 104 | for early adopters and testers. If you are interested in influencing the |
| 105 | direction of the Android framework, |
| 106 | <a href="{@docRoot}preview/setup-sdk.html">give the L Developer Preview a |
| 107 | try</a> and send us your feedback!</p> |
| 108 | |
| 109 | <p class="caution"><strong>Caution:</strong>You should not publish apps |
| 110 | using L Developer Preview to the Google Play store.</p> |
| 111 | |
| 112 | <h2 id="Behaviors">Important Behavior Changes</h2> |
| 113 | |
| 114 | <p>If you have previously published an app for Android, be aware that your app |
| 115 | might be affected by changes in L.</p> |
| 116 | |
| 117 | <h3 id="BehaviorNotifications">If your app implements notifications...</h3> |
| 118 | |
| 119 | <p>Notifications will be drawn with dark text atop white (or very light) |
| 120 | backgrounds to match the new material design widgets. Make sure that all your |
| 121 | notifications look right with the new color scheme. You should remove or update |
| 122 | assets and text styles that involve color. The system will automatically invert |
| 123 | action icons in notifications. Use |
| 124 | {@code android.app.Notification.Builder.setColor()} to set an accent color |
| 125 | in a circle behind your {@code Notification.icon} image.</p> |
| 126 | |
| 127 | <p>The system will ignore all non-alpha channels in action icons and the main |
| 128 | notification icon, so you should assume that these icons will be alpha-only. |
| 129 | </p> |
| 130 | |
| 131 | <p>If you are currently adding sounds and vibrations to your notifications by |
| 132 | using the {@link android.media.Ringtone}, {@link android.media.MediaPlayer}, |
| 133 | or {@link android.os.Vibrator} classes, make sure to remove this code so that |
| 134 | the system can present notifications correctly in Do not disturb mode. You |
| 135 | should use the {@link android.app.Notification.Builder} methods instead to add |
| 136 | sounds and vibration. |
| 137 | </p> |
| 138 | |
| 139 | <h3 id="BehaviorMediaControl">If your app uses RemoteControlClient...</h3> |
| 140 | |
| 141 | <p>Lockscreens in L will not show transport controls for your |
| 142 | {@link android.media.RemoteControlClient}. Instead, your app can provide |
| 143 | media playback control from the lockscreen through a media notification. This |
| 144 | gives your app more control over the presentation of media buttons, while |
| 145 | providing a consistent experience for users across the lockscreen and |
Quddus Chong | d50a6f8 | 2014-06-15 12:13:18 -0700 | [diff] [blame] | 146 | unlocked device.</p> |
Robert Ly | 2055529 | 2014-06-13 23:28:19 -0700 | [diff] [blame] | 147 | |
| 148 | <p>You must call {@code Notification.Builder.setVisibility(Notification.VISIBILITY_PUBLIC)} to mark your media notification as safe to reveal, even when the lockscreen is secured |
| 149 | with a PIN, pattern, or password.</p> |
| 150 | |
| 151 | <h3 id="BehaviorFullscreen">If your app uses fullScreenIntent...</h3> |
| 152 | |
| 153 | <p>Notifications now appear in a small floating window if all these conditions |
| 154 | are met: the user’s activity is in fullscreen mode, the screen is on, and the |
| 155 | device is unlocked. If your app implements fullscreen activities, make sure that |
| 156 | these heads-up notifications are presented correctly.</p> |
| 157 | |
| 158 | <h3 id="BehaviorGetRecentTasks">If your app uses ActivityManager.getRecentTasks()...</h3> |
| 159 | |
| 160 | <p>With the introduction of the new document tasks feature in L (see below), |
| 161 | the {@code android.app.ActivityManager.getRecentTasks()} method is now |
| 162 | deprecated to improve user privacy. For backwards |
| 163 | compatibility, it will still return a small subset of its data including the |
| 164 | calling application’s own tasks and possibly some other non-sensitive tasks |
| 165 | such as home. If your app is using this method to retrieve its own tasks, |
| 166 | use {@code android.app.ActivityManager.getAppTasks()} instead to retrieve that |
| 167 | information.</p> |
| 168 | |
| 169 | <h2 id="UI">User Interface</h2> |
| 170 | |
| 171 | <h3 id="MaterialDesign">Material design support</h3> |
| 172 | |
Ricardo Cervera | d3e426b | 2014-06-15 16:01:28 -0700 | [diff] [blame^] | 173 | <p>The L Developer Preview adds support for the material design style. You can create |
Robert Ly | 2055529 | 2014-06-13 23:28:19 -0700 | [diff] [blame] | 174 | material design apps that are visually dynamic and have UI element transitions |
| 175 | which feel natural and delightful to users. This support includes:</p> |
| 176 | <ul> |
Ricardo Cervera | d3e426b | 2014-06-15 16:01:28 -0700 | [diff] [blame^] | 177 | <li>The Material theme</li> |
| 178 | <li>View shadows</li> |
| 179 | <li>The {@code RecyclerView} widget</li> |
| 180 | <li>Drawable animation and styling effects</li> |
| 181 | <li>Material design animation and activity transition effects</li> |
| 182 | <li>Animators for view properties based on the state of a view</li> |
| 183 | <li>Customizable UI widgets and app bars with color palettes that you control</li> |
Robert Ly | 2055529 | 2014-06-13 23:28:19 -0700 | [diff] [blame] | 184 | </ul> |
| 185 | <p>To learn more about adding material design functionality to your app, see |
Quddus Chong | d50a6f8 | 2014-06-15 12:13:18 -0700 | [diff] [blame] | 186 | <a href="{@docRoot}preview/material/index.html">Material design on Android</a>.</p> |
Robert Ly | 2055529 | 2014-06-13 23:28:19 -0700 | [diff] [blame] | 187 | |
| 188 | <h3 id="LockscreenNotifications">Lockscreen notifications</h3> |
Ricardo Cervera | d3e426b | 2014-06-15 16:01:28 -0700 | [diff] [blame^] | 189 | <p>Lockscreens in the L Developer Preview have the ability to present notifications. |
| 190 | Users can choose via <em>Settings</em> whether to allow sensitive notification |
Robert Ly | 2055529 | 2014-06-13 23:28:19 -0700 | [diff] [blame] | 191 | content to be shown over a secure lockscreen.</p> |
| 192 | |
| 193 | <p>Your app can control the level of detail visible when its notifications are |
Ricardo Cervera | d3e426b | 2014-06-15 16:01:28 -0700 | [diff] [blame^] | 194 | displayed over the secure lockscreen. To control the visibility level, call |
Robert Ly | 2055529 | 2014-06-13 23:28:19 -0700 | [diff] [blame] | 195 | {@code android.app.Notification.Builder.setVisibility()} and specify one of these |
| 196 | values:</p> |
| 197 | <ul> |
| 198 | <li>{@code VISIBILITY_PRIVATE}. Shows basic information, such as the |
| 199 | notification’s icon, but hides the notification’s full content. If you want to |
| 200 | provide a redacted public version of your notification for the system to display |
Ricardo Cervera | d3e426b | 2014-06-15 16:01:28 -0700 | [diff] [blame^] | 201 | on a secure lockscreen, set the public notification object in the <code>publicVersion</code> |
| 202 | field.</li> |
Robert Ly | 2055529 | 2014-06-13 23:28:19 -0700 | [diff] [blame] | 203 | <li>{@code VISIBILITY_PUBLIC}. Shows the notification’s full content. This is |
Ricardo Cervera | d3e426b | 2014-06-15 16:01:28 -0700 | [diff] [blame^] | 204 | the system default if visibility is left unspecified.</li> |
Robert Ly | 2055529 | 2014-06-13 23:28:19 -0700 | [diff] [blame] | 205 | <li>{@code VISIBILITY_SECRET}. Shows only the most minimal information, |
Ricardo Cervera | d3e426b | 2014-06-15 16:01:28 -0700 | [diff] [blame^] | 206 | excluding even the notification’s icon.</li> |
Robert Ly | 2055529 | 2014-06-13 23:28:19 -0700 | [diff] [blame] | 207 | </ul> |
| 208 | |
| 209 | <h3 id="NotificationsMetadata">Notifications metadata</h3> |
| 210 | <p>The L Developer Preview uses metadata associated with your app notifications |
| 211 | to more intelligently sort your notifications. The metadata you set also |
Ricardo Cervera | d3e426b | 2014-06-15 16:01:28 -0700 | [diff] [blame^] | 212 | controls how the system presents your app notifications when the user is in <em>Do |
| 213 | not disturb</em> mode. When constructing your notification, you can call the |
Robert Ly | 2055529 | 2014-06-13 23:28:19 -0700 | [diff] [blame] | 214 | following methods in {@code android.app.Notification.Builder}:</p> |
| 215 | |
| 216 | <ul> |
| 217 | <li>{@code setCategory()}. Allows the system to handle your app notifications |
Ricardo Cervera | d3e426b | 2014-06-15 16:01:28 -0700 | [diff] [blame^] | 218 | in <em>Do not disturb mode</em> (for example, if your notification represents an |
| 219 | incoming call, instant message, or alarm).</li> |
Robert Ly | 2055529 | 2014-06-13 23:28:19 -0700 | [diff] [blame] | 220 | <li>{@code setPriority()}. Notifications with the priority field set to |
| 221 | {@code PRIORITY_MAX} or {@code PRIORITY_HIGH} will appear in a small floating |
Ricardo Cervera | d3e426b | 2014-06-15 16:01:28 -0700 | [diff] [blame^] | 222 | window if the notification also has sound or vibration.</li> |
Robert Ly | 2055529 | 2014-06-13 23:28:19 -0700 | [diff] [blame] | 223 | <li>{@code addPerson()}. Allows you to add a list of people to a notification. |
| 224 | Your app can use this to signal to the system that it should group together |
| 225 | notifications from the specified people, or rank notifications from these |
Ricardo Cervera | d3e426b | 2014-06-15 16:01:28 -0700 | [diff] [blame^] | 226 | people as being more important.</li> |
Robert Ly | 2055529 | 2014-06-13 23:28:19 -0700 | [diff] [blame] | 227 | </ul> |
| 228 | |
Ricardo Cervera | d3e426b | 2014-06-15 16:01:28 -0700 | [diff] [blame^] | 229 | <h3 id="Recents">Concurrent documents and activities in the Recents screen</h3> |
Robert Ly | 2055529 | 2014-06-13 23:28:19 -0700 | [diff] [blame] | 230 | |
| 231 | <p>In previous releases, the |
| 232 | <a href="{@docRoot}design/get-started/ui-overview.html">Recents screen</a> |
| 233 | could only display a single task for each app that the user interacted with |
| 234 | most recently. The L Developer Preview allows your app to open additional tasks |
| 235 | for concurrent activities or documents. This feature facilitates multitasking |
| 236 | by letting users quickly switch between individual activities and documents |
| 237 | from the Recents screen. Examples of such concurrent tasks might include web |
| 238 | pages in a browser app, documents in a productivity app, concurrent matches in |
| 239 | a game, or chats in a messaging app. Your app can manage its tasks |
| 240 | through the {@code android.app.ActivityManager.AppTask} class.</p> |
| 241 | |
| 242 | <p>To insert a logical break so that the system treats your activity as a new |
| 243 | document, use {@code android.content.Intent.FLAG_ACTIVITY_NEW_DOCUMENT} when |
| 244 | launching the activity with {@link android.app.Activity#startActivity(android.content.Intent) startActivity()}. You can also get this behavior by declaring the |
| 245 | <a href="{@docRoot}guide/topics/manifest/activity-element.html"><activity></a> |
| 246 | attribute {@code documentLaunchMode="intoExisting"} or {@code ="always"} in your |
| 247 | manifest.</p> |
| 248 | |
| 249 | <p>You can also mark that a task should be removed from the Recents screen |
| 250 | when all its activities are closed by using {@code android.content.Intent.FLAG_ACTIVITY_AUTO_REMOVE_FROM_RECENTS} when starting the root activity for |
| 251 | the task. You can also set this behavior for an activity by declaring the |
| 252 | <a href="{@docRoot}guide/topics/manifest/activity-element.html"><activity></a> |
| 253 | attribute {@code autoRemoveFromRecents=“true”} in your manifest.</p> |
| 254 | |
| 255 | <p>To avoid cluttering the Recents screen, you can set the maximum number of |
| 256 | tasks from your app that can appear in the Recents screen through the |
| 257 | <a href="{@docRoot}guide/topics/manifest/application-element.html"><application></a> attribute {@code android:maxRecent}. The current maximum that can be specified |
| 258 | is 100 tasks per user.</a></p> |
| 259 | |
| 260 | <h3 id="WebView">WebView updates</h3> |
| 261 | <p>The L Developer Preview updates the {@link android.webkit.WebView} |
| 262 | implementation to Chromium M36, bringing security and stability enhancements, |
| 263 | as well as bug fixes. The default user-agent string for a |
| 264 | {@link android.webkit.WebView} running on the L Developer Preview has |
| 265 | been updated to incorporate 36.0.0.0 as the version number.</p> |
| 266 | |
| 267 | <p>Additionally, this release brings support for the |
| 268 | <a href="https://dvcs.w3.org/hg/audio/raw-file/tip/webaudio/specification.html">WebAudio</a>, <a href="https://www.khronos.org/webgl/">WebGL</a>, and |
| 269 | <a href="http://www.webrtc.org/">WebRTC</a> open standards. To learn more about |
| 270 | the new features included in this release, see <a href="https://developer.chrome.com/multidevice/webview/overview">WebView for Android</a>.</p> |
| 271 | |
| 272 | <h2 id="UserInput">User Input</h2> |
| 273 | |
| 274 | <h3 id="IME">IME bug fixes and improvements</h3> |
| 275 | |
| 276 | <p>Beginning in the L Developer Preview, users can more easily switch between |
| 277 | all input method editors (IME) <a href="{@docRoot}guide/topics/text/creating-input-method.html">supported by the platform</a>. Performing the designated |
| 278 | switching action (usually touching a Globe icon on the soft keyboard) will cycle |
| 279 | among all such IMEs. This change takes place in |
| 280 | {@code android.view.inputmethod.InputMethodManager.shouldOfferSwitchingToNextInputMethod()}.</p> |
| 281 | |
| 282 | <p>In addition, the framework will now check whether the next IME includes a |
| 283 | switching mechanism at all, thus supporting switching to the IME after it. An |
| 284 | IME with a switching mechanism will not cycle to an IME without one. This |
| 285 | change takes place in |
| 286 | {@code android.view.inputmethod.InputMethodManager.switchToNextInputMethod()}. |
| 287 | |
| 288 | <p>To see an example of how to use the updated IME-switching APIs, refer to the |
| 289 | updated soft-keyboard implementation sample in this release.</p> |
| 290 | |
| 291 | <h2 id="Animations">Animation & Graphics</h2> |
| 292 | |
| 293 | <h3 id="OpenGLES-3-1">Support for OpenGL ES 3.1</h3> |
| 294 | <p>The L Developer Preview adds Java interfaces and native support for OpenGL |
| 295 | ES 3.1. Key new functionality provided in OpenGL ES 3.1 includes:</p> |
| 296 | |
| 297 | <ul> |
| 298 | <li>Compute shaders |
| 299 | <li>Separate shader objects |
| 300 | <li>Indirect draw commands |
| 301 | <li>Enhanced texturing functionality |
| 302 | <li>Shading language improvements |
| 303 | <li>Optional extensions for per-sample shading, advanced blending modes, and more |
| 304 | <li>Backward compatibility with OpenGL ES 2.0 and 3.0 |
| 305 | </ul> |
| 306 | |
| 307 | <p>The Java interface for OpenGL ES 3.1 on Android is provided with GLES31. When using OpenGL ES 3.1, be sure that you declare it in your manifest file with the |
| 308 | <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html">{@code <uses-feature>}</a> tag and the {@code android:glEsVversion} attribute. For example:</p> |
| 309 | |
| 310 | <pre> |
| 311 | <manifest> |
| 312 | <uses-feature android:glEsVersion="0x00030001" /> |
| 313 | ... |
| 314 | </manifest> |
| 315 | </pre> |
| 316 | |
| 317 | <p>For more information about using OpenGL ES, including how to check the device’s supported OpenGL ES version at runtime, see the <a href="{@docRoot}/guide/topics/graphics/opengl.html">OpenGL ES API guide</a>.</p> |
| 318 | |
| 319 | <h2 id="Multimedia">Multimedia</h2> |
| 320 | |
| 321 | <h3 id="Camera=v2">Camera v2 API</h3> |
| 322 | |
| 323 | <p>The L Developer Preview introduces the new {@code android.hardware.camera2} |
| 324 | API to facilitate fine grain photo capture and image processing. You can now programmatically access the camera devices available to the system with {@code CameraManager.getCameraIdList()} and connect to a specific device with {@code CameraManager.openCamera()}. To start capturing images, you |
| 325 | need to create a {@code CameraCaptureSession} and specify the |
| 326 | {@link android.view.Surface} objects to send the captured images. The {@code CameraCaptureSession} can be configured to take single shots or multiple images |
| 327 | in a burst.</p> |
| 328 | |
| 329 | <p>To be notified when new images are captured, implement the |
| 330 | {@code CameraCaptureSession.CaptureListener()} interface and set it in your |
| 331 | capture request. Now when the system completes the image capture request, your |
| 332 | {@code CameraCaptureSession.CaptureListener()} receives a call to |
| 333 | {@code onCaptureCompleted()}, providing you with the image capture metadata in a |
| 334 | {@code CaptureResult}.</p> |
| 335 | |
| 336 | <h3 id="AudioPlayback">Audio playback</h3> |
| 337 | <p>This release includes the following changes for |
| 338 | {@code android.media.AudioTrack}:</p> |
| 339 | <ul> |
| 340 | <li>Your app can now supply audio data in floating-point format |
| 341 | ({@code android.media.AudioFormat.ENCODING_PCM_FLOAT}). This permits greater |
| 342 | dynamic range, more consistent precision, and greater headroom. Floating-point arithmetic is especially useful during intermediate calculations. Playback |
| 343 | end-points use integer format for audio data, and with lower bit-depth. In L |
| 344 | Developer Preview, portions of the internal pipeline are not yet floating-point. |
| 345 | <li>Your app can now supply audio data as a {@code ByteBuffer}, in the same |
| 346 | format as provided by {@code MediaCodec}. |
| 347 | <li>The {@code WRITE_NON_BLOCKING} option can simplify buffering and |
| 348 | multithreading for some apps. |
| 349 | </ul> |
| 350 | |
| 351 | <h3 id="MediaPlaybackControl">Media playback control</h3> |
| 352 | <p>You can now build your own media controller app with the new |
| 353 | {@code android.media.session.MediaController} class, which provides |
| 354 | simplified transport controls APIs that replace those in |
| 355 | {@code android.media.RemoteControlClient}. The {@code MediaController} class |
| 356 | allows thread-safe control of playback from a non UI process, making it easier |
| 357 | to control your media playback service from your app’s user interface. |
| 358 | |
| 359 | <p>You can also create multiple controllers to send playback commands, |
| 360 | media keys, and other events to the same ongoing |
| 361 | {@code android.media.session.MediaSession}. When you add a controller, you must |
| 362 | call {@code MediaSession.getSessionToken()} to request an access |
| 363 | token in order for your app to interact with the session.</p> |
| 364 | |
| 365 | <p>Send transport commands such as "play", "stop", "skip", and |
| 366 | "set rating" by using {@code MediaController.TransportControls}. To handle |
| 367 | in-bound media transport commands from controllers attached to the session, you |
| 368 | should override the callback methods in |
| 369 | {@code MediaSession.TransportControlsCallback}.</p> |
| 370 | |
| 371 | <p>You can also create rich notifications that allow playback control tied to a |
| 372 | media session with the new {@code android.app.Notification.MediaStyle} class.</p> |
| 373 | |
| 374 | <h2 id="Storage">Storage</h2> |
| 375 | |
| 376 | <h3 id="DirectorySelection">Directory selection</h3> |
| 377 | |
| 378 | <p>The L Developer Preview extends the <a href="{@docRoot}guide/topics/providers/document-provider.html">Storage Access Framework</a> to let users |
| 379 | select an entire directory, rather than individual files, to give your app |
| 380 | read/write access to media files. When a directory is selected, your app also |
| 381 | has access to all its child directories and content.</p> |
| 382 | |
| 383 | <p>To get the absolute paths to directories on external storage devices where |
| 384 | applications can store media files, call the |
| 385 | {@code android.content.Context.getExternalMediaDirs()} method. No additional |
| 386 | permissions are needed by your app to read or write to the returned paths. |
| 387 | External storage devices here are those considered by the system to be a |
| 388 | permanent part of the device, and includes emulated external storage and |
| 389 | physical media slots such as SD cards in battery compartments.</p> |
| 390 | |
| 391 | <p>If you want to access a document in an existing directory, call the |
| 392 | {@code android.provider.DocumentsContract.buildDocumentViaUri()} method and pass |
| 393 | in a Uri representing the path to the parent directory and the target document |
| 394 | ID. The method returns a new {@link android.net.Uri} with which your app can |
| 395 | use to write media content with {@code DocumentsContract.createDocument()}. |
| 396 | |
| 397 | <h2 id="Wireless">Wireless & Connectivity</h2> |
| 398 | |
| 399 | <h3 id="Multinetwork">Dynamic network selection and seamless handoff</h3> |
| 400 | <p>The L Developer Preview provides new multi-networking APIs for your app to |
| 401 | dynamically scan for available networks with specific capabilities, and |
| 402 | establish a connection to them. This is useful when your app requires a |
| 403 | specialized network, such as an SUPL, MMS, or carrier-billing network, or if |
| 404 | you want to send data using a particular type of transport protocol.</p> |
| 405 | |
| 406 | <p>To select and connect to a network dynamically from your app, first |
| 407 | instantiate a {@code android.net.ConnectivityManager}. Next, create a |
| 408 | {@code android.net.NetworkRequest} to specify the network features and transport |
| 409 | type your app is interested in. To start scanning for suitable networks, call |
| 410 | {@code ConnectivityManager.requestNetwork()} or |
| 411 | {@code ConnectivityManager.registerNetworkCallback(), and pass in the |
| 412 | {@code NetworkRequest} object and an implementation of |
| 413 | {@code ConnectivityManager.NetworkCallbackListener}.</p> |
| 414 | |
| 415 | <p>When the system detects a suitable network, it connects to the network and |
| 416 | invokes the {@code NetworkCallbackListener.onAvailable()} callback. You can use |
| 417 | the {@code android.net.Network} object from the callback to get additional |
| 418 | information about the network, or to establish a socket connection.</p> |
| 419 | |
| 420 | <h3 id="BluetoothBroadcasting">Bluetooth broadcasting</h3> |
| 421 | <p>Android 4.3 introduced platform support for <a href="{@docRoot}guide/topics/connectivity/bluetooth-le.html">Bluetooth Low Energy</a> |
| 422 | (BLE) in the central role. In the L Developer Preview, an Android device can now |
| 423 | act as a Bluetooth LE <em>peripheral device</em> and make its presence known to |
| 424 | nearby devices. For instance, you can build apps that allow a device to |
| 425 | function as a pedometer or health monitor and communicate its data with another |
| 426 | BLE device.</p> |
| 427 | |
| 428 | <p>The new {@code android.bluetooth.le} APIs enable your apps to broadcast advertisements, scan for responses, and form connections with nearby BLE devices. |
| 429 | You must add the {@code android.permission.BLUETOOTH_ADMIN} permission in your |
| 430 | manifest in order for your app to use the new advertising and scanning features.</a> |
| 431 | |
| 432 | <p>To begin Bluetooth LE advertising so that other devices can discover the |
| 433 | device running your app, call {@code android.bluetooth.le.BluetoothAdvertiser.startAdvisertising()} and pass in an implementation of the |
| 434 | {@code android.bluetooth.le.AdvertiseCallback} class to report the success |
| 435 | or failure of the advertising operation.</p> |
| 436 | |
| 437 | <p>Conversely, if you want to scan for Bluetooth LE devices nearby, call |
| 438 | {@code android.bluetooth.le.BluetoothLeScanner.startScan()} and pass in an |
| 439 | implementation of {@code android.bluetooth.le.ScanCallback} to report if a |
| 440 | Bluetooth LE advertisement is found. Optionally, you can pass in filters to scan |
| 441 | for a specific type of device.</p> |
| 442 | |
| 443 | <h3 id="NFCEnhancements">NFC enhancements</h3> |
| 444 | <p>The L Developer Preview adds these enhancements to enable wider and more |
| 445 | flexible use of NFC:</p> |
| 446 | |
| 447 | <ul> |
| 448 | <li>Android Beam is now available in the share menu. |
Quddus Chong | d50a6f8 | 2014-06-15 12:13:18 -0700 | [diff] [blame] | 449 | <li>Support for the <a href="http://www.wi-fi.org/discover-wi-fi/wi-fi-direct">Wi-fi Direct standard</a>. |
Robert Ly | 2055529 | 2014-06-13 23:28:19 -0700 | [diff] [blame] | 450 | <li>Your app can invoke the Android Beam on the user’s device to share data by |
| 451 | calling {@code android.nfc.NfcAdapter.invokeBeam()}. This avoids the need for |
| 452 | the user to manually tap the device against another NFC-capable device to |
| 453 | complete the data transfer. |
| 454 | <li>Use the new {@code android.nfc.NdefRecord.createTextRecord()} method if |
| 455 | you want to create an NDEF record containing UTF-8 text data. |
| 456 | <li>If you are developing a payment app, you now have the ability to |
| 457 | register an NFC application ID (AID) dynamically by calling |
| 458 | {@code android.nfc.cardemulation.CardEmulation.registerAidsForService()}. |
| 459 | You can also use {@code android.nfc.cardemulation.CardEmulation.setPreferredService()} |
| 460 | to set the preferred card emulation service that should be used when a specific |
| 461 | activity is in the foreground. |
| 462 | </ul> |
| 463 | |
| 464 | <h2 id="Power">Power Efficiency</h2> |
| 465 | |
| 466 | <h3 id="JobScheduler">Scheduling jobs</h3> |
| 467 | <p>The L Developer Preview provides a new {@code android.app.job.JobScheduler} |
Quddus Chong | d50a6f8 | 2014-06-15 12:13:18 -0700 | [diff] [blame] | 468 | API that lets you optimize battery life by defining jobs for the system to run |
| 469 | asynchronously at a later time, such as when the device is charging. This is |
Robert Ly | 2055529 | 2014-06-13 23:28:19 -0700 | [diff] [blame] | 470 | useful when you want to defer non user-facing units of work, have application |
| 471 | code that accesses the network, or want to run a number of tasks as a batch on |
| 472 | a regular schedule.</p> |
| 473 | |
| 474 | <p>A {@code android.app.job.JobInfo} object encapsulates such a unit of work, |
| 475 | and provides an exact description of the criteria you are scheduling.</p> |
| 476 | |
| 477 | <p>Use the {@code android.app.job.JobInfo.Builder} to configure how the |
| 478 | scheduled task should run. You can schedule the task to run under specific |
| 479 | conditions such as only while the device is charging, when connected to an |
| 480 | unmetered network, or when the system deems the device is idle.</p> |
| 481 | |
| 482 | <p>For example, you can add code like this to run your task on an |
| 483 | unmetered network:</p> |
| 484 | |
| 485 | <pre> |
| 486 | JobInfo uploadTask = new JobInfo.Builder(mJobId, mServiceComponent) |
| 487 | .setRequiredNetworkCapabilities(JobInfo.NetworkType.UNMETERED) |
| 488 | .build(); |
| 489 | |
| 490 | JobScheduler jobScheduler = |
| 491 | (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE) |
| 492 | jobScheduler.schedule(uploadTask); |
| 493 | </pre> |
| 494 | |
| 495 | <h3 id="PowerMeasurementTools">Developer tools and APIs for power measurement</h3> |
| 496 | <p>The L Developer Preview provides several new developer tools and APIs to help |
| 497 | you better measure and understand your app's power usage.</p> |
| 498 | |
| 499 | <dl> |
| 500 | <dt><strong>batterystats</strong></dt> |
| 501 | <dd> |
| 502 | <p>The {@code dumpsys batterystats} command allows you to generate interesting |
| 503 | statistical data about battery usage on a device, organized by unique user ID |
| 504 | (UID). The statistics generated by the tool include:</p> |
| 505 | |
| 506 | <ul> |
| 507 | <li>History of battery related events |
| 508 | <li>Global statistics for the device |
| 509 | <li>Approximated power use per UID and system component |
| 510 | <li>Per-app mobile ms per packet |
| 511 | <li>System UID aggregated statistics |
| 512 | <li>App UID aggregated statistics |
| 513 | </ul> |
| 514 | |
Quddus Chong | d50a6f8 | 2014-06-15 12:13:18 -0700 | [diff] [blame] | 515 | <p>Use the {@code --help} option to learn about the various options for |
| 516 | tailoring the output. For example, to run the tool to print battery usage |
| 517 | statistics since the device was last charged for a given app package, run this |
| 518 | command: |
Robert Ly | 2055529 | 2014-06-13 23:28:19 -0700 | [diff] [blame] | 519 | <pre> |
| 520 | $ adb shell dumpsys batterystats --charged <package-name> |
| 521 | </pre> |
| 522 | </dd> |
| 523 | |
| 524 | <dt><strong>Battery Historian</strong></dt> |
| 525 | <dd> |
| 526 | <p>The Battery Historian tool ({@code historian.par}) analyzes L-based Android |
| 527 | bug reports and creates an HTML visualization of power-related events. It can |
| 528 | also visualize power consumption data from a power monitor, and will attempt to |
| 529 | map power usage to the wakelocks seen. You can find the Battery Historian tool |
| 530 | in {@code <sdk>/tools}.</p> |
| 531 | |
| 532 | <p>For best results, you should first enable full wakelock reporting to allow |
| 533 | the Battery Historian tool to monitor uninterrupted over an extended period of |
| 534 | time:</p> |
| 535 | <pre> |
| 536 | $ adb shell dumpsys batterystats --enable full-wake-history |
| 537 | </pre> |
| 538 | |
| 539 | <p>You should also reset battery statistics at the beginning of a |
| 540 | measurement:</p> |
| 541 | <pre> |
| 542 | $ adb shell dumpsys batterystats --reset |
| 543 | </pre> |
| 544 | |
| 545 | <p>To generate an HTML visualization:</p> |
| 546 | <pre> |
| 547 | $ historian.par [-p powerfile] bugreport.txt > out.html |
| 548 | </pre> |
| 549 | </dd> |
| 550 | |
| 551 | <dt><strong>On-device power management</strong></dt> |
| 552 | <dd> |
| 553 | <p>You can use the {@code android.os.BatteryManager} API to obtain power |
| 554 | consumption information based on the battery fuel gauge included in Android |
| 555 | phones and tablets. This is useful in cases when it is not convenient to |
| 556 | connect external measurement equipment to the Android device.</p> |
| 557 | <p>To retrieve the battery properties, call {@code BatteryManager.getIntProperty()} |
| 558 | or {@code BatteryManager.getLongProperty()}. The properties available, the |
| 559 | exact resolution of the values of each, and other characteristics such as |
| 560 | update frequency depend on the particular device being tested.</p> |
| 561 | |
| 562 | <p>The following properties can be inspected on all Android devices:</p> |
| 563 | |
| 564 | <table> |
| 565 | <tr> |
| 566 | <th>Property</th> |
| 567 | <th>Description</th> |
| 568 | </tr> |
| 569 | <tr> |
| 570 | <td>{@code BatteryManager.BATTERY_PROPERTY_CHARGE_COUNTER}</td> |
| 571 | <td>Remaining battery capacity in microampere-hours.</td> |
| 572 | </tr> |
| 573 | <tr> |
| 574 | <td>{@code BatteryManager.BATTERY_PROPERTY_CURRENT_NOW}</td> |
| 575 | <td>Instantaneous battery current in microamperes.</td> |
| 576 | </tr> |
| 577 | <tr> |
| 578 | <td>{@code BatteryManager.BATTERY_PROPERTY_CURRENT_AVERAGE}</td> |
| 579 | <td>Average battery current in microamperes</td> |
| 580 | </tr> |
| 581 | <tr> |
| 582 | <td>{@code BatteryManager.BATTERY_PROPERTY_CAPACITY}</td> |
| 583 | <td>Remaining battery capacity as an integer percentage.</td> |
| 584 | </tr> |
| 585 | <tr> |
| 586 | <td>{@code BatteryManager.BATTERY_PROPERTY_ENERGY_COUNTER}</td> |
| 587 | <td>Remaining energy in nanowatt-hours.</td> |
| 588 | </tr> |
| 589 | </table> |
| 590 | <dd> |
| 591 | </dl> |
| 592 | |
| 593 | <h2 id="Enterprise">Enterprise</h2> |
| 594 | <h3 id="ManagedProvisioning">Managed provisioning</h3> |
| 595 | |
| 596 | <p>The L Developer Preview provides new functionality for running apps within |
| 597 | an enterprise environment:</p> |
| 598 | <ul> |
| 599 | <li><strong>Create managed user profiles</strong>. A device administrator can |
| 600 | initiate a managed provisioning process to enroll a user device with an |
| 601 | existing personal account into a co-present but separate managed profile that |
| 602 | the administrator controls. |
| 603 | <li><strong>Set device owner scope</strong>. Device administrators can also |
| 604 | apply managed provisioning to configure a device that has no previous user |
| 605 | accounts installed, so that they have full control over the device. |
| 606 | </ul> |
| 607 | |
| 608 | <p>To start the manged provisioning process, send |
| 609 | {@code ACTION_PROVISION_MANAGED_PROFILE} in an {@link android.content.Intent}. A |
| 610 | user may be associated with more than one managed profile. To get a list of the |
| 611 | managed profiles associated with the user, call |
| 612 | {@code android.os.UserManager.getUserProfiles()}.</p> |
| 613 | |
| 614 | <p>Once a managed profile is created for a user, apps that are managed by the |
| 615 | device administrator will appear alongside non-managed apps in the user’s |
| 616 | Launcher, Recent apps screen, and notifications. A device policy management app |
| 617 | can make the managed apps visually prominent by appending a “work” badge to the |
| 618 | icon drawable with {@code android.os.UserManager.getBadgeDrawableForUser()}.</p> |
| 619 | |
| 620 | <p>If you are developing a Launcher app, you can use the new {@code android.content.pm.LauncherApps} class to get a list of launchable activities for the current user |
| 621 | and any associated managed profiles.</p> |
| 622 | |
| 623 | <h2 id="Printing">Printing Framework</h2> |
| 624 | |
| 625 | <h3 id="PDFRender">Render PDF as bitmap</h3> |
| 626 | <p>You can now render PDF document pages into bitmap images for printing by |
| 627 | using the new {@code android.graphics.pdf.PdfRenderer} class. You must specify a |
| 628 | {@code ParcelFileDescriptor} that is seekable (that is, the file can be randomly |
| 629 | accessed) on which the system writes the the printable content. Your app can |
| 630 | obtain a page for rendering with {@code openPage()}, then call {@code render()} |
| 631 | to turn the opened {@code PdfRenderer.Page} into a bitmap. You can also set |
| 632 | additional parameters if you only wan to convert a portion of the document into |
| 633 | a bitmap image (for example, to implement <a href="http://en.wikipedia.org/wiki/Tiled_rendering">tile rendering</a> in order to zoom in on the document).</p> |
| 634 | |
| 635 | <h2 id="TestingA11y">Testing & Accessibility </h2> |
| 636 | |
| 637 | <h3 id="Testing A11yImprovements">Testing and accessibility improvements</h3> |
| 638 | <p>The L Developer Preview adds the following support for testing and |
| 639 | accessibility:</p> |
| 640 | |
| 641 | <ul> |
| 642 | <li>You can use the new {@code android.app.UiAutomation.getWindowAnimationFrameStats()} |
| 643 | and {@code android.app.UiAutomation.getWindowContentFrameStats()} methods to |
| 644 | capture frame statistics for window animations and content. This lets you |
| 645 | write instrumentation tests to evaluate if the app under test is rendering |
| 646 | frames at a sufficient refresh frequency to provide a smooth user experience. |
| 647 | <li>You can execute shell commands from your instrumentation test with the new |
| 648 | {@code android.app.UiAutomation.executeShellCommand()}. The command execution |
| 649 | is similar to running 'adb shell' from a host connected to the device. This |
| 650 | allows you to use shell based tools such as {@code dumpsys}, {@code am}, |
| 651 | {@code content}, and {@code pm}. |
| 652 | <li>Accessibility services and test tools that use the accessibility APIs |
| 653 | (such as <a href="{@docRoot}tools/help/uiautomator/index.html">UiAutomator</a>) |
| 654 | can now retrieve detailed information about the properties of windows on the |
| 655 | screen that sighted users can interact with. To retrieve a list of |
| 656 | {@code android.view.accessibility.AccessibilityWindowInfo} representing the |
| 657 | windows information, call the new |
| 658 | {@code android.accessibilityservice.AccessibilityService.getWindows()} method. |
| 659 | <li>You can use the new {@code android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction} to define standard or customized |
| 660 | actions to perform on an {@code android.view.accessibility.AccessibilityNodeInfo}. |
| 661 | The new {@code AccessibilityAction} class replaces the actions-related APIs |
| 662 | previously found in {@code AccessibilityNodeInfo}. |
| 663 | </ul> |
| 664 | |
| 665 | <h2 id="manifest">Manifest Declarations</h2> |
| 666 | |
| 667 | <h3 id="ManifestFeatures">Declarable required features</h3> |
| 668 | <p>The following values are now supported in the <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html">{@code <uses-feature>}</a> element so you |
| 669 | can ensure that your app is installed only on devices that provide the features |
| 670 | your app needs.</p> |
| 671 | |
| 672 | <ul> |
| 673 | <li>{@code FEATURE_LEANBACK}. Declares that your app must be installed only on devices that support the <a href="{@docRoot}tv}">Android TV</a> user interface. Example: |
| 674 | <pre> |
| 675 | <uses-feature android:name="android.software.leanback" |
| 676 | android:required="true" /> |
| 677 | </pre> |
| 678 | |
| 679 | <li>{@code FEATURE_MANAGEDPROFILES}. Declares that your app must only be installed on devices that support managed profiles for enterprise users. Example: |
| 680 | <pre> |
| 681 | <uses-feature android:name="android.software.managedprofiles" |
| 682 | android:required="true" /> |
| 683 | </pre> |
| 684 | <li>{@code FEATURE_WEBVIEW}. Declares that your app must only be installed on devices that fully implement the android.webkit.* APIs. Example: |
| 685 | <pre> |
| 686 | <uses-feature android:name="android.software.webview" |
| 687 | android:required="true" /> |
| 688 | </pre> |
| 689 | </ul> |
| 690 | |
| 691 | <h3 id="ManifestPermissions">User permissions</h3> |
| 692 | <p>The following values are now supported in the <a href="{@docRoot}guide/topics/manifest/uses-permission-element.html">{@code <uses-permission>}</a> to declare the |
| 693 | permissions your app requires in order to access certain APIs. |
| 694 | |
| 695 | <ul> |
| 696 | <li>{@code SIM_COMMUNICATION}. Required to communicate with a SIM card using |
| 697 | logical channels. |
| 698 | </ul> |