1 page.title=Android 3.1 APIs 2 excludeFromSuggestions=true 3 sdk.platform.version=3.1 4 sdk.platform.apiLevel=12 5 @jd:body 6 7 <div id="qv-wrapper"> 8 <div id="qv"> 9 10 <h2>In this document</h2> 11 <ol> 12 <li><a href="#api">API Overview</a></li> 13 <li><a href="#api-level">API Level</a></li> 14 </ol> 15 16 <h2>Reference</h2> 17 <ol> 18 <li><a 19 href="{@docRoot}sdk/api_diff/12/changes.html">API 20 Differences Report »</a> </li> 21 </ol> 22 23 </div> 24 </div> 25 26 27 <p><em>API Level:</em> <strong>{@sdkPlatformApiLevel}</strong></p> 28 29 <p>For developers, the Android {@sdkPlatformVersion} platform 30 ({@link android.os.Build.VERSION_CODES#HONEYCOMB_MR1}) is available as a 31 downloadable component for the Android SDK. The downloadable platform includes 32 an Android library and system image, as well as a set of emulator skins and 33 more. The downloadable platform includes no external libraries.</p> 34 35 <p>For developers, the Android {@sdkPlatformVersion} platform is available as a 36 downloadable component for the Android SDK. The downloadable platform includes 37 an Android library and system image, as well as a set of emulator skins and 38 more. To get started developing or testing against Android {@sdkPlatformVersion}, 39 use the Android SDK Manager to download the platform into your SDK.</p> 40 41 42 43 <h2 id="#api" style="margin-top:1.5em;">API Overview</h2> 44 45 <p>The sections below provide a technical overview of what's new for developers 46 in Android 3.1, including new features and changes in the framework API since 47 the previous version.</p> 48 49 <h3 id="usb">USB APIs</h3> 50 51 <p>Android 3.1 introduces powerful new APIs for 52 integrating connected peripherals with applications running on the platform. 53 The APIs are based on a USB (Universal Serial Bus) stack and services that are 54 built into the platform, including support for both USB host and device 55 interactions. Using the APIs, developers can create applications that are able to 56 discover, communicate with, and manage a variety of device types connected over 57 USB. </p> 58 59 <p>The stack and APIs distinguish two basic types of USB hardware, based on 60 whether the Android-powered device is acting as host or the external hardware 61 is acting as host: </p> 62 63 <ul> 64 <li>A <em>USB device</em> is a piece of connected hardware that depends on the 65 Android-powered device to serve as host. For example, most input devices, mice, 66 and joysticks are USB devices, as are many cameras, hubs, and so on.</li> 67 <li>A <em>USB accessory</em> is a piece of connected hardware that has a USB 68 host controller, provides power, and is designed to communicate with 69 Android-powered devices over USB, A variety of peripherals can connect as 70 accessories, from robotics controllers to musical equipment, exercise bicycles, 71 and more.</li> 72 </ul> 73 74 <p>For both types — USB devices and USB accessories — the 75 platform's USB APIs support discovery by intent broadcast when attached or 76 detached, as well as standard interfaces, endpoints, and transfer modes 77 (control, bulk, and interrupt).</p> 78 79 <p>The USB APIs are available in the package {@link android.hardware.usb}. The 80 central class is {@link android.hardware.usb.UsbManager}, which provides 81 helper methods for identifying and communicating with 82 both USB devices and USB accessories. Applications can acquire an instance of 83 {@link android.hardware.usb.UsbManager} and then query for the list of attached 84 devices or accessories and then communicate with or manage them. 85 {@link android.hardware.usb.UsbManager} also declares intent actions that the 86 system broadcasts, to announce when a USB device or accessory is attached or 87 detached.</p> 88 89 <p>Other classes include:</p> 90 91 <ul> 92 <li>{@link android.hardware.usb.UsbDevice}, a class representing external 93 hardware connected as a USB device (with the Android-powered device acting as 94 host).</li> 95 <li>{@link android.hardware.usb.UsbAccessory}, representing external hardware 96 connected as the USB host (with the Android-powered device acting as a USB 97 device).</li> 98 <li>{@link android.hardware.usb.UsbInterface} and {@link 99 android.hardware.usb.UsbEndpoint}, which provide access to standard USB 100 interfaces and endpoints for a device.</li> 101 <li>{@link android.hardware.usb.UsbDeviceConnection} and {@link 102 android.hardware.usb.UsbRequest}, for sending and receiving data and control 103 messages to or from a USB device, sychronously and asynchronously. 104 <li>{@link android.hardware.usb.UsbConstants}, which provides constants for 105 declaring endpoint types, device classes, and so on.</li> 106 </ul> 107 108 <p>Note that although the USB stack is built into the platform, actual support 109 for USB host and open accessory modes on specific devices is determined by 110 their manufacturers. In particular, host mode relies on appropriate USB 111 controller hardware in the Android-powered device. </p> 112 113 <p>Additionally, developers can request filtering on Google Play, such that 114 their applications are not availabe to users whose devices do not provide the 115 appropriate USB support. To request filtering, add one or both of the elements 116 below to the application manifest, as appropriate: </p> 117 118 <ul> 119 <li>If the application should only be visible to devices that support USB 120 host mode (connection of USB devices), declare this element: 121 <p style="margin-left:1.5em;"><code><uses-feature 122 android:name="android.hardware.usb.host" 123 android:required="true"></code></p> 124 </li> 125 <li>If the application should only be visible to devices that support USB 126 accessories (connection of USB hosts), declare this element: 127 <p style="margin-left:1.5em;"><code><uses-feature 128 android:name="android.hardware.usb.accessory" 129 android:required="true"></code></p> 130 </li> 131 </ul> 132 133 <p>For complete information about how to develop applications that interact with 134 USB accessories, please see the 135 <a href="{@docRoot}guide/topics/connectivity/usb/index.html">developer documentation</a>.</p> 136 137 <p class="note">To look at sample applications that use the USB host API, see <a 138 href="{@docRoot}resources/samples/USB/AdbTest/index.html">ADB Test</a> and <a 139 href="{@docRoot}resources/samples/USB/MissileLauncher/index.html">Missile 140 Launcher</a></p> 141 142 <h3>MTP/PTP API</h3> 143 144 <p>Android 3.1 exposes a new MTP API that lets applications interact directly 145 with connected cameras and other PTP devices. The new API makes it easy for an 146 application to receive notifications when devices are attached and removed, 147 manage files and storage on those devices, and transfer files and metadata to 148 and from them. The MTP API implements the PTP (Picture Transfer Protocol) subset 149 of the MTP (Media Transfer Protocol) specification.</p> 150 151 <p>The MTP API is available in the {@link android.mtp} package and provides 152 these classes: </p> 153 154 <ul> 155 <li>The {@link android.mtp.MtpDevice} encapsulates an MTP device that is 156 connected over the USB host bus. An application can instantiate an object of 157 this type and then use its methods to get information about the device and 158 objects stored on it, as well as opening the connection and transferring data. 159 Some of the methods include: 160 <ul> 161 <li>{@link android.mtp.MtpDevice#getObjectHandles(int, int, int) 162 getObjectHandles()} returns a list of handles for all objects on the device that 163 match a specified format and parent. To get information about an object, an 164 application can pass a handle to {@link android.mtp.MtpDevice#getObjectInfo(int) 165 getObjectInfo()}.</li> 166 <li>{@link android.mtp.MtpDevice#importFile(int, java.lang.String) 167 importFile()} lets an application copy data for an object to a file in external 168 storage. This call may block for an arbitrary amount of time depending on the 169 size of the data and speed of the devices, so should be made from a spearate 170 thread.</li> 171 <li>{@link 172 android.mtp.MtpDevice#open(android.hardware.usb.UsbDeviceConnection) open()} 173 lets an application open a connected MTP/PTP device. </li> 174 <li>{@link android.mtp.MtpDevice#getThumbnail(int) getThumbnail()} returns 175 the thumbnail of the object as a byte array. </li> 176 </ul> 177 </li> 178 <li>{@link android.mtp.MtpStorageInfo} holds information about about a storage 179 unit on an MTP device, corresponding to the StorageInfo Dataset described in 180 section 5.2.2 of the MTP specification. Methods in the class let an application 181 get a storage units description string, free space, maximum storage capacity, 182 storage ID, and volume identifier.</li> 183 <li>{@link android.mtp.MtpDeviceInfo} holds information about an MTP device 184 corresponding to the DeviceInfo Dataset described in section 5.1.1 of the MTP 185 specification. Methods in the class let applications get a devices 186 manufacturer, model, serial number, and version.</li> 187 <li>{@link android.mtp.MtpObjectInfo} holds information about an object stored 188 on an MTP device, corresponding to the ObjectInfo Dataset described in section 189 5.3.1 of the MTP specification. Methods in the class let applications get an 190 objects size, data format, association type, creation date, and thumbnail 191 information.</li> 192 <li>{@link android.mtp.MtpConstants} provides constants for declaring MTP file 193 format codes, association type, and protection status.</li> 194 </ul> 195 196 <h3 id="motionevents">Support for new input devices and motion events</h3> 197 198 <p>Android 3.1 extends the input subsystem to support new input devices and new 199 types of motion events, across all views and windows. Developers can build on 200 these capabilities to let users interact with their applications using mice, 201 trackballs, joysticks, gamepads, and other devices, in addition to keyboards and 202 touchscreens. </p> 203 204 <p>For handling mouse, scrollwheel, and trackball input, the platform supports 205 two new motion event actions:</p> 206 <ul> 207 <li>{@link android.view.MotionEvent#ACTION_SCROLL}, which describes the pointer 208 location at which a non-touch scroll motion, such as from a mouse scroll wheel, 209 took place. In the MotionEvent, the value of the {@link 210 android.view.MotionEvent#AXIS_HSCROLL} and {@link 211 android.view.MotionEvent#AXIS_VSCROLL} axes specify the relative scroll 212 movement. </li> 213 <li>{@link android.view.MotionEvent#ACTION_HOVER_MOVE}, reports the current 214 position of the mouse when no buttons are pressed, as well as any intermediate 215 points since the last <code>HOVER_MOVE</code> event. Hover enter and exit 216 notifications are not yet supported.</li> 217 </ul> 218 219 <p>To support joysticks and gamepads, the {@link android.view.InputDevice} class 220 includes these new input device sources:</p> 221 <ul> 222 <li>{@link android.view.InputDevice#SOURCE_CLASS_JOYSTICK} — the source 223 device has joystick axes.</li> 224 <li>{@link android.view.InputDevice#SOURCE_CLASS_BUTTON} — the source 225 device has buttons or keys.</li> 226 <li>{@link android.view.InputDevice#SOURCE_GAMEPAD} — the source device 227 has gamepad buttons such as {@link android.view.KeyEvent#KEYCODE_BUTTON_A} 228 or {@link android.view.KeyEvent#KEYCODE_BUTTON_B}. Implies 229 {@link android.view.InputDevice#SOURCE_CLASS_BUTTON}</li> 230 <li>{@link android.view.InputDevice#SOURCE_JOYSTICK} — the source device 231 has joystick axes. Implies SOURCE_CLASS_JOYSTICK.</li> 232 </ul> 233 234 <p>To describe motion events from these new sources, as well as those from mice 235 and trackballs, the platform now defines axis codes on {@link 236 android.view.MotionEvent}, similar to how it defines key codes on {@link 237 android.view.KeyEvent}. New axis codes for joysticks 238 and game controllers include 239 {@link android.view.MotionEvent#AXIS_HAT_X}, {@link 240 android.view.MotionEvent#AXIS_HAT_Y}, {@link 241 android.view.MotionEvent#AXIS_RTRIGGER}, {@link 242 android.view.MotionEvent#AXIS_ORIENTATION}, {@link 243 android.view.MotionEvent#AXIS_THROTTLE}, and many others. 244 Existing {@link android.view.MotionEvent} axes are represented by {@link 245 android.view.MotionEvent#AXIS_X}, {@link android.view.MotionEvent#AXIS_Y}, 246 {@link android.view.MotionEvent#AXIS_PRESSURE}, {@link 247 android.view.MotionEvent#AXIS_SIZE}, {@link 248 android.view.MotionEvent#AXIS_TOUCH_MAJOR}, {@link 249 android.view.MotionEvent#AXIS_TOUCH_MINOR}, {@link 250 android.view.MotionEvent#AXIS_TOOL_MAJOR}, {@link 251 android.view.MotionEvent#AXIS_TOOL_MINOR}, and {@link 252 android.view.MotionEvent#AXIS_ORIENTATION}.</p> 253 254 <p>Additionally, {@link android.view.MotionEvent} defines a number of generic 255 axis codes that are used when the framework does not know how to map a 256 particular axis. Specific devices can use the generic axis codes to pass custom 257 motion data to applications. For a full list of axes and their intended 258 interpretations, see the {@link android.view.MotionEvent} class documentation. 259 </p> 260 261 <p>The platform provides motion events to applications in batches, so a single 262 event may contain a current position and multiple so-called historical movements. 263 Applications should use {@link android.view.MotionEvent#getHistorySize()} to get 264 the number of historical samples, then retrieve and process all historical 265 samples in order using {@link 266 android.view.MotionEvent#getHistoricalAxisValue(int, int, int) 267 getHistoricalAxisValue()}. After that, applications should process the current 268 sample using {@link android.view.MotionEvent#getAxisValue(int) getAxisValue()}. 269 </p> 270 271 <p>Some axes can be retrieved using special accessor methods. For example, 272 instead of calling {@link android.view.MotionEvent#getAxisValue(int) 273 getAxisValue()}, applications can call {@link android.view.MotionEvent#getX(int) 274 getX()}. Axes that have built-in accessors include {@link 275 android.view.MotionEvent#AXIS_X}, {@link android.view.MotionEvent#AXIS_Y}, 276 {@link android.view.MotionEvent#AXIS_PRESSURE}, {@link 277 android.view.MotionEvent#AXIS_SIZE}, {@link 278 android.view.MotionEvent#AXIS_TOUCH_MAJOR}, {@link 279 android.view.MotionEvent#AXIS_TOUCH_MINOR}, {@link 280 android.view.MotionEvent#AXIS_TOOL_MAJOR}, {@link 281 android.view.MotionEvent#AXIS_TOOL_MINOR}, and {@link 282 android.view.MotionEvent#AXIS_ORIENTATION}.</p> 283 284 <p>Each input device has a unique, system-assigned ID and may also provide 285 multiple sources. When a device provides multiple sources, more than one source 286 can provide axis data using the same axis. For example, a touch event coming 287 from the touch source uses the X axis for screen position data, while a joystick 288 event coming from the joystick source will use the X axis for the stick position 289 instead. For this reason, it's important for applications to interpret axis 290 values according to the source from which they originate. When handling a motion 291 event, applications should use methods on the {@link android.view.InputDevice} 292 class to determine the axes supported by a device or source. Specifically, 293 applications can use {@link android.view.InputDevice#getMotionRanges() 294 getMotionRanges()} to query for all axes of a device or all axes of a given 295 source of the device. In both cases, the range information for axes returned in 296 the {@link android.view.InputDevice.MotionRange} object specifies the source for 297 each axis value.</p> 298 299 <p>Finally, since the motion events from joysticks, gamepads, mice, and 300 trackballs are not touch events, the platform adds a new callback method for 301 passing them to a {@link android.view.View} as "generic" motion events. 302 Specifically, it reports the non-touch motion events to 303 {@link android.view.View}s through a call to {@link 304 android.view.View#onGenericMotionEvent(android.view.MotionEvent) 305 onGenericMotionEvent()}, rather than to {@link 306 android.view.View#onTouchEvent(android.view.MotionEvent) 307 onTouchEvent()}.</p> 308 309 <p>The platform dispatches generic motion events differently, depending on the 310 event source class. {@link android.view.InputDevice#SOURCE_CLASS_POINTER} events 311 go to the {@link android.view.View} under the pointer, similar to how touch 312 events work. All others go to the currently focused {@link android.view.View}. 313 For example, this means a {@link android.view.View} must take focus in order to 314 receive joystick events. If needed, applications can handle these events at the 315 level of Activity or Dialog by implementing {@link 316 android.view.View#onGenericMotionEvent(android.view.MotionEvent) 317 onGenericMotionEvent()} there instead.</p> 318 319 <p class="note">To look at a sample application that uses joystick motion 320 events, see <a 321 href="{@docRoot}resources/samples/ApiDemos/src/com/example/android/apis/view/GameControllerInput.html">GameControllerInput</a> 322 and <a 323 href="{@docRoot}resources/samples/ApiDemos/src/com/example/android/apis/view/GameView.html">GameView</a>.</p> 324 325 <h3>RTP API</h3> 326 327 <p>Android 3.1 exposes an API to its built-in RTP (Real-time Transport Protocol) 328 stack, which applications can use to manage on-demand or interactive data 329 streaming. In particular, apps that provide VOIP, push-to-talk, conferencing, 330 and audio streaming can use the API to initiate sessions and transmit or receive 331 data streams over any available network.</p> 332 333 <p>The RTP API is available in the {@link android.net.rtp} package. Classes 334 include: </p> 335 <ul> 336 <li>{@link android.net.rtp.RtpStream}, the base class of streams that send and 337 receive network packets with media payloads over RTP.</li> 338 <li>{@link android.net.rtp.AudioStream}, a subclass of {@link 339 android.net.rtp.RtpStream} that carries audio payloads over RTP.</li> 340 <li>{@link android.net.rtp.AudioGroup}, a local audio hub for managing and 341 mixing the device speaker, microphone, and {@link android.net.rtp.AudioStream}.</li> 342 <li>{@link android.net.rtp.AudioCodec}, which holds a collection of codecs that 343 you define for an {@link android.net.rtp.AudioStream}.</li> 344 </ul> 345 346 <p>To support audio conferencing and similar usages, an application instantiates 347 two classes as endpoints for the stream:</p> 348 349 <ul> 350 <li>{@link android.net.rtp.AudioStream} specifies a remote endpoint and consists 351 of network mapping and a configured {@link android.net.rtp.AudioCodec}.</li> 352 <li>{@link android.net.rtp.AudioGroup} represents the local endpoint for one 353 or more {@link android.net.rtp.AudioStream}s. The {@link android.net.rtp.AudioGroup} mixes 354 all the {@link android.net.rtp.AudioStream}s and optionally interacts with the device 355 speaker and the microphone at the same time.</li> 356 </ul> 357 358 <p>The simplest usage involves a single remote endpoint and local endpoint. 359 For more complex usages, please refer to the limitations described for 360 {@link android.net.rtp.AudioGroup}.</p> 361 362 <p>To use the RTP API, applications must request permission from the user by 363 declaring <code><uses-permission 364 android:name="android.permission.INTERNET"></code> 365 in their manifest files. To acquire the device microphone, the <code><uses-permission 366 android:name="android.permission.RECORD_AUDIO"></code> permission is also required.</p> 367 368 <h3 id="resizewidgets">Resizable app widgets</h3> 369 370 <p>Starting in Android 3.1, developers can make their homescreen widgets 371 resizeable — horizontally, vertically, or on both axes. Users touch-hold a 372 widget to show its resize handles, then drag the horizontal and/or vertical 373 handles to change the size on the layout grid. </p> 374 375 <p>Developers can make any Home screen widget resizeable by defining a 376 <code>resizeMode</code> attribute in the widget's {@link 377 android.appwidget.AppWidgetProviderInfo} metadata. Values for the 378 <code>resizeMode</code> attribute include "horizontal", "vertical", and "none". 379 To declare a widget as resizeable horizontally and vertically, supply the value 380 "horizontal|vertical". 381 382 <p>Here's an example: </p> 383 384 <pre><appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" 385 android:minWidth="294dp" 386 android:minHeight="72dp" 387 android:updatePeriodMillis="86400000" 388 android:previewImage="@drawable/preview" 389 android:initialLayout="@layout/example_appwidget" 390 android:configure="com.example.android.ExampleAppWidgetConfigure" 391 android:resizeMode="horizontal|vertical" > 392 </appwidget-provider></pre> 393 394 <p>For more information about Home screen widgets, see the <a 395 href="{@docRoot}guide/topics/appwidgets/index.html">App Widgets</a> 396 documentation.</p> 397 398 <h3 id="animation" style="margin-top:1.25em;">Animation framework</h3> 399 400 <ul> 401 <li>New ViewPropertyAnimator class 402 <ul> 403 <li>A new {@link android.view.ViewPropertyAnimator} class provides a 404 convenient 405 way for developers to animate select properties on {@link android.view.View} objects. The class 406 automaties and optimizes the animation of the properties and makes it easier to 407 manage multiple simulataneous animations on a {@link android.view.View} object. 408 <p>Using the {@link android.view.ViewPropertyAnimator} is straightforward. To animate properties for 409 a {@link android.view.View}, call {@link android.view.View#animate()} to 410 construct a {@link android.view.ViewPropertyAnimator} object for that {@link android.view.View}. Use the 411 methods on the {@link android.view.ViewPropertyAnimator} to specify what property to 412 animate and how to animate it. For example, to fade the {@link android.view.View} to transparent, 413 call <code>alpha(0);</code>. The {@link android.view.ViewPropertyAnimator} object 414 handles the details of configuring the underlying {@link 415 android.animation.Animator} class and starting it, then rendering the 416 animation.</p></li> 417 </ul> 418 </li> 419 <li>Animation background color 420 <ul> 421 <li>New {@link android.view.animation.Animation#getBackgroundColor()} and 422 {@link android.view.animation.Animation#setBackgroundColor(int)} methods let 423 you get/set the background color behind animations, for window animations 424 only. Currently the background must be black, with any desired alpha level.</li> 425 </ul> 426 </li> 427 <li>Getting animated fraction from <code>ViewAnimator</code> 428 <ul> 429 <li>A new {@link android.animation.ValueAnimator#getAnimatedFraction()} 430 method 431 lets you get the current animation fraction — the elapsed/interpolated 432 fraction used in the most recent frame update — from a {@link 433 android.animation.ValueAnimator}.</li> 434 </ul> 435 </li> 436 </ul> 437 438 <h3 "ui">UI framework</h3> 439 <ul> 440 <li>Forced rendering of a layer 441 <ul> 442 <li>A new {@link android.view.View#buildLayer()} method lets an application 443 force a View's layer to be created and the View rendered into it immediately. 444 For example, an application could use this method to render a View into its 445 layer before starting an animation. If the View is complex, rendering it into 446 the layer before starting the animation will avoid skipping frames.</li> 447 </ul> 448 </li> 449 <li>Camera distance 450 <ul> 451 <li>Applications can use a new method 452 {@link android.view.View#setCameraDistance(float)} to set the distance from the 453 camera 454 to a View. This gives applications improved control over 3D transformations of 455 the View, such as rotations. </li> 456 </ul> 457 </li> 458 <li>Getting a calendar view from a DatePicker 459 <ul> 460 <li>A new {@link android.widget.DatePicker#getCalendarView()} method 461 lets you get a {@link android.widget.CalendarView} from a {@link 462 android.widget.DatePicker} 463 instance.</li> 464 </ul> 465 </li> 466 <li>Getting callbacks when views are detached 467 <ul> 468 <li>A new {@link android.view.View.OnAttachStateChangeListener} lets you 469 receive 470 callbacks when a View is attached or detached from its window. Use {@link 471 android.view.View#addOnAttachStateChangeListener(android.view.View.OnAttachStateChangeListener) addOnAttachStateChangeListener()} 472 to add a listener and {@link 473 android.view.View#removeOnAttachStateChangeListener(android.view.View.OnAttachStateChangeListener) addOnAttachStateChangeListener()} to remove it.</li> 474 </ul> 475 </li> 476 <li>Fragment breadcrumb listener, new onInflate() signature 477 <ul> 478 <li>A new method, {@link 479 android.app.FragmentBreadCrumbs#setOnBreadCrumbClickListener(android.app.FragmentBreadCrumbs.OnBreadCrumbClickListener) setOnBreadCrumbClickListener()}, 480 provides a hook to let 481 applications intercept fragment-breadcrumb clicks and take any action needed 482 before going to the backstack entry or fragment that was clicked. </li> 483 <li>In the {@link android.app.Fragment} class, {@link 484 android.app.Fragment#onInflate(android.util.AttributeSet, android.os.Bundle) 485 onInflate(attrs, savedInstanceState)} is deprecated. Please use {@link 486 android.app.Fragment#onInflate(android.app.Activity, android.util.AttributeSet, 487 android.os.Bundle) onInflate(activity, attrs, savedInstanceState)} instead.</li> 488 </ul> 489 </li> 490 <li>Display search result in new tab 491 <ul> 492 <li>An {@link android.app.SearchManager#EXTRA_NEW_SEARCH} data key for {@link 493 android.content.Intent#ACTION_WEB_SEARCH} intents lets you open a search in a 494 new browser tab, rather than in an existing one.</li> 495 </ul> 496 </li> 497 498 <li>Drawable text cursor 499 <ul> 500 <li>You can now specify a drawable to use as the text cursor using the new 501 resource attribute {@link android.R.attr#textCursorDrawable}.</li> 502 </ul> 503 </li> 504 <li>Setting displayed child in remote views 505 <ul> 506 <li>A new convenience method, {@link 507 android.widget.RemoteViews#setDisplayedChild(int, int) setDisplayedChild(viewId, 508 childIndex)}, is available in {@link android.widget.RemoteViews} subclasses, to 509 let you set the child displayed in {@link android.widget.ViewAnimator} and 510 {@link android.widget.AdapterViewAnimator} subclasses such as {@link 511 android.widget.AdapterViewFlipper}, {@link android.widget.StackView}, {@link 512 android.widget.ViewFlipper}, and {@link android.widget.ViewSwitcher}.</li> 513 </ul> 514 </li> 515 <li>Generic keys for gamepads and other input devices 516 <ul> 517 <li>{@link android.view.KeyEvent} adds a range of generic keycodes to 518 accommodate gamepad buttons. The class also adds 519 {@link android.view.KeyEvent#isGamepadButton(int)} and several other 520 helper methods for working with keycodes.</li> 521 </ul> 522 </li> 523 </ul> 524 525 <h3 id="graphics" style="margin-top:1.3em;">Graphics</h3> 526 527 <ul> 528 <li>Helpers for managing bitmaps 529 <ul> 530 <li>{@link android.graphics.Bitmap#setHasAlpha(boolean)} lets an app indicate that 531 all of the pixels in a Bitmap are known to be opaque (false) or that some of the 532 pixels may contain non-opaque alpha values (true). Note, for some configs (such 533 as RGB_565) this call is ignored, since it does not support per-pixel alpha 534 values. This is meant as a drawing hint, as in some cases a bitmap that is known 535 to be opaque can take a faster drawing case than one that may have non-opaque 536 per-pixel alpha values. </li> 537 <li>{@link android.graphics.Bitmap#getByteCount()} gets a Bitmap's size in 538 bytes.</li> 539 <li>{@link android.graphics.Bitmap#getGenerationId()} lets an application find 540 out whether a Bitmap has been modified, such as for caching.</li> 541 <li>{@link android.graphics.Bitmap#sameAs(android.graphics.Bitmap)} determines 542 whether a given Bitmap differs from the current Bitmap, in dimension, 543 configuration, or pixel data. </li> 544 </ul> 545 </li> 546 <li>Setting camera location and rotation 547 <ul> 548 <li>{@link android.graphics.Camera} adds two new methods {@link 549 android.graphics.Camera#rotate(float, float, float) rotate()} and {@link 550 android.graphics.Camera#setLocation(float, float, float) setLocation()} for 551 control of the 552 camera's location, for 3D transformations.</li> 553 </ul> 554 </li> 555 </ul> 556 557 <h3 id="network" style="margin-top:1.25em;">Network</h3> 558 559 <ul> 560 <li>High-performance Wi-Fi lock 561 <ul> 562 <li>A new high-performance Wi-Fi lock lets applications maintain 563 high-performance Wi-Fi connections even when the device screen is off. 564 Applications that stream music, video, or voice for long periods can acquire the 565 high-performance Wi-Fi lock to ensure streaming performance even when the screen 566 is off. Because it uses more power, applications should acquire the 567 high-performance Wi-Fi when there is a need for a long-running active 568 connection. 569 <p>To create a high-performance lock, pass {@link 570 android.net.wifi.WifiManager#WIFI_MODE_FULL_HIGH_PERF} as the lock mode in a 571 call to {@link android.net.wifi.WifiManager#createWifiLock(int, 572 java.lang.String) createWifiLock()}.</p></li> 573 </ul> 574 </li> 575 <li>More traffic stats 576 <ul> 577 <li>Applications can now access statistics about more types of network usage 578 using new methods in {@link android.net.TrafficStats}. Applications can use the 579 methods to get UDP stats, packet count, TCP transmit/receive payload bytes and 580 segments for a given UID.</li> 581 </ul> 582 </li> 583 <li>SIP auth username 584 <ul> 585 <li>Applications can now get and set the SIP auth username for a profile 586 using 587 the new methods {@link android.net.sip.SipProfile#getAuthUserName() 588 getAuthUserName()} and {@link 589 android.net.sip.SipProfile.Builder#setAuthUserName(java.lang.String) 590 setAuthUserName()}.</li> 591 </ul> 592 </li> 593 </ul> 594 595 596 <h3 id="download" style="margin-top:1.25em;">Download Manager</h3> 597 <ul> 598 <li>Handling of completed downloads 599 <ul> 600 <li>Applications can now initiate downloads that notify users only on 601 completion. To initiate this type of download, applications pass {@link 602 android.app.DownloadManager.Request#VISIBILITY_VISIBLE_NOTIFY_ONLY_COMPLETION} 603 in the {@link 604 android.app.DownloadManager.Request#setNotificationVisibility(int) 605 setNotificationVisibility()} method of 606 the a request object.</li> 607 <li>A new method, {@link 608 android.app.DownloadManager#addCompletedDownload(java.lang.String, 609 java.lang.String, boolean, java.lang.String, java.lang.String, long, boolean) 610 addCompletedDownload()}, lets an application add a file to the 611 downloads database, so that it can be managed by the Downloads application.</li> 612 </ul> 613 </li> 614 <li>Show downloads sorted by size 615 <ul> 616 <li>Applications can start the Downloads application in sort-by-size mode by 617 adding the new extra {@link 618 android.app.DownloadManager#INTENT_EXTRAS_SORT_BY_SIZE} to an {@link 619 android.app.DownloadManager#ACTION_VIEW_DOWNLOADS} intent.</li> 620 </ul> 621 </li> 622 </ul> 623 624 <h3 id="ime" style="margin-top:1.25em;">IME framework</h3> 625 626 <ul> 627 <li>Getting an input method's extra value key 628 <ul><li>The {@link android.view.inputmethod.InputMethodSubtype} adds the 629 method 630 {@link 631 android.view.inputmethod.InputMethodSubtype#containsExtraValueKey(java.lang.String) containsExtraValueKey()} to check whether an ExtraValue string is stored 632 for the subtype and 633 the method {@link 634 android.view.inputmethod.InputMethodSubtype#getExtraValueOf(java.lang.String) 635 getExtraValueOf()} to extract a specific key value from the ExtraValue hashmap. 636 </li> 637 </ul> 638 </li> 639 </ul> 640 641 <h3 id="media" style="margin-top:1.25em;">Media</h3> 642 643 <ul> 644 <li>New streaming audio formats 645 <ul> 646 <li>The media framework adds built-in support for raw ADTS AAC content, for 647 improved streaming audio, as well as support for FLAC audio, for highest quality 648 (lossless) compressed audio content. See the <a 649 href="{@docRoot}guide/appendix/media-formats.html">Supported Media Formats</a> 650 document for more information.</p></li> 651 </ul> 652 </li> 653 </ul> 654 655 <h3 id="launchcontrols" style="margin-top:1.25em;">Launch controls on stopped 656 applications</h3> 657 658 <p>Starting from Android 3.1, the system's package manager keeps track of 659 applications that are in a stopped state and provides a means of controlling 660 their launch from background processes and other applications.</p> 661 662 <p>Note that an application's stopped state is not the same as an Activity's 663 stopped state. The system manages those two stopped states separately.</p> 664 665 <p>The platform defines two new intent flags that let a sender specify 666 whether the Intent should be allowed to activate components in stopped 667 application.</p> 668 669 <ul> 670 <li>{@link android.content.Intent#FLAG_INCLUDE_STOPPED_PACKAGES} — 671 Include intent filters of stopped applications in the list of potential targets 672 to resolve against. </li> 673 <li>{@link android.content.Intent#FLAG_EXCLUDE_STOPPED_PACKAGES} — 674 Exclude intent filters of stopped applications from the list of potential 675 targets.</li> 676 </ul> 677 678 <p>When neither or both of these flags is defined in an intent, the default 679 behavior is to include filters of stopped applications in the list of 680 potential targets.</p> 681 682 <p>Note that the system adds {@link 683 android.content.Intent#FLAG_EXCLUDE_STOPPED_PACKAGES} <em>to all broadcast 684 intents</em>. It does this to prevent broadcasts from background services from 685 inadvertently or unnecessarily launching components of stoppped applications. 686 A background service or application can override this behavior by adding the 687 {@link android.content.Intent#FLAG_INCLUDE_STOPPED_PACKAGES} flag to broadcast 688 intents that should be allowed to activate stopped applications.</p> 689 690 <p>Applications are in a stopped state when they are first installed but are not 691 yet launched and when they are manually stopped by the user (in Manage 692 Applications).</p> 693 694 <h3 id="installnotification">Notification of application first launch and upgrade</h3> 695 696 <p>The platform adds improved notification of application first launch and 697 upgrades through two new intent actions:</p> 698 699 <ul> 700 <li>{@link android.content.Intent#ACTION_PACKAGE_FIRST_LAUNCH} — Sent to 701 the installer package of an application when that application is first launched 702 (that is, the first time it is moved out of a stopped state). The data 703 contains the name of the package. </li> 704 705 <li>{@link android.content.Intent#ACTION_MY_PACKAGE_REPLACED} — Notifies 706 an application that it was updated, with a new version was installed over 707 an existing version. This is only sent to the application that was replaced. It 708 does not contain any additional data. To receive it, declare an intent filter 709 for this action. You can use the intent to trigger code that helps get your 710 application back in proper running shape after an upgrade. 711 712 <p>This intent is sent directly to the application, but only if the application 713 was upgraded while it was in started state (not in a stopped state).</p></li> 714 715 </ul> 716 717 <h3 id="other">Core utilities</h3> 718 719 <ul> 720 <li>LRU cache 721 <ul> 722 <li>A new {@link android.util.LruCache} class lets your applications benefit 723 from efficient caching. Applications can use the class to reduce the time spent 724 computing or downloading data from the network, while maintaining a sensible 725 memory footprint for the cached data.{@link android.util.LruCache} is a cache 726 that holds strong references to a limited number of values. Each time a value is 727 accessed, it is moved to the head of a queue. When a value is added to a full 728 cache, the value at the end of that queue is evicted and may become eligible for 729 garbage collection.</li> 730 </ul> 731 </li> 732 <li>File descriptor as <code>int</code> 733 <ul> 734 <li>You can now get the native file descriptor int for a {@link 735 android.os.ParcelFileDescriptor} using either of the new methods {@link 736 android.os.ParcelFileDescriptor#getFd()} or {@link 737 android.os.ParcelFileDescriptor#detachFd()}. </li> 738 </ul> 739 </li> 740 </ul> 741 742 743 744 745 746 747 <h3 id="webkit" style="margin-top:1.25em;">WebKit</h3> 748 749 <ul> 750 751 <li>File scheme cookies 752 <ul> 753 <li>The {@link android.webkit.CookieManager} now supports cookies that use 754 the 755 <code>file:</code> URI scheme. You can use {@link 756 android.webkit.CookieManager#setAcceptFileSchemeCookies(boolean) 757 setAcceptFileSchemeCookies()} to 758 enable/disable support for file scheme cookies, before constructing an instance 759 of <code>WebView</code> or <code>CookieManager</code>. In a 760 <code>CookieManager</code> instance, you can check whether file scheme cookies 761 is enabled by calling {@link 762 android.webkit.CookieManager#allowFileSchemeCookies()}.</li> 763 </ul> 764 </li> 765 <li>Notification of login request 766 <ul> 767 <li>To support the browser autologin features introduced in Android 3.0, the 768 new 769 method {@link 770 android.webkit.WebViewClient#onReceivedLoginRequest(android.webkit.WebView,java.lang.String, java.lang.String, java.lang.String) onReceivedLoginRequest()} 771 notifies the host 772 application that an autologin request for the user was processed. </li> 773 </ul> 774 </li> 775 <li>Removed classes and interfaces 776 <ul> 777 <li>Several classes and interfaces were removed from the public API, after 778 previously being in deprecated state. See the <a 779 href="{@docRoot}sdk/api_diff/{@sdkPlatformApiLevel}/changes.html">API 780 Differences Report</a> for more information.</p></li> 781 </ul> 782 </li> 783 </ul> 784 785 786 787 <h3 id="browser" style="margin-top:1.25em;">Browser</h3> 788 789 <p>The Browser application adds the following features to support web 790 applications:</p> 791 792 <ul> 793 <li>Support for inline playback of video embedded in HTML5 794 <code><video></code> tag. Playback is hardware-accelerated where possible. 795 </li> 796 <li>Layer support for fixed position elements for all sites (mobile and 797 desktop).</li> 798 </ul> 799 800 801 802 803 804 <h3 id="features">New feature constants</h3> 805 806 <p>The platform adds new hardware feature constants that developers can declare 807 in their application manifests, to inform external entities such as Google 808 Play of the application's requirement for new hardware capabilities supported 809 in this version of the platform. Developers declare these and other feature 810 constants in <a 811 href="{@docRoot}guide/topics/manifest/uses-feature-element.html">{@code 812 <uses-feature>}</a> manifest elements. 813 814 <ul> 815 <li>{@link android.content.pm.PackageManager#FEATURE_USB_ACCESSORY 816 android.hardware.usb.accessory} — The application uses the <a href="#usb">USB 817 API</a> to communicate with external hardware devices connected over USB and 818 function as hosts.</li> 819 <li>{@link android.content.pm.PackageManager#FEATURE_USB_HOST 820 android.hardware.usb.host} — The application uses the <a href="#usb">USB API</a> 821 to communicate with external hardware devices connected over USB and function as 822 devices.</li> 823 </ul> 824 825 <p>Google Play filters applications based on features declared in <a 826 href="{@docRoot}guide/topics/manifest/uses-feature-element.html">{@code 827 <uses-feature>}</a> manifest elements. For more information about 828 declaring features in an application manifest, read <a 829 href="{@docRoot}google/play/filters.html">Google Play 830 Filters</a>.</p> 831 832 833 834 <h3 id="api-diff">API Differences Report</h3> 835 836 <p>For a detailed view of all API changes in Android {@sdkPlatformVersion} (API 837 Level 838 {@sdkPlatformApiLevel}), see the <a 839 href="{@docRoot}sdk/api_diff/{@sdkPlatformApiLevel}/changes.html">API 840 Differences Report</a>.</p> 841 842 843 844 845 846 <h2 id="api-level">API Level</h2> 847 848 <p>The Android {@sdkPlatformVersion} platform delivers an updated version of 849 the framework API. The Android {@sdkPlatformVersion} API 850 is assigned an integer identifier — 851 <strong>{@sdkPlatformApiLevel}</strong> — that is 852 stored in the system itself. This identifier, called the "API Level", allows the 853 system to correctly determine whether an application is compatible with 854 the system, prior to installing the application. </p> 855 856 <p>To use APIs introduced in Android {@sdkPlatformVersion} in your application, 857 you need compile the application against the Android library that is provided in 858 the Android {@sdkPlatformVersion} SDK platform. Depending on your needs, you 859 might 860 also need to add an <code>android:minSdkVersion="{@sdkPlatformApiLevel}"</code> 861 attribute to the <code><uses-sdk></code> element in the application's 862 manifest.</p> 863 864 <p>For more information, read <a href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#ApiLevels">What is API 865 Level?</a></p> 866