1page.title=Android 3.1 APIs
2excludeFromSuggestions=true
3sdk.platform.version=3.1
4sdk.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
19href="{@docRoot}sdk/api_diff/12/changes.html">API
20Differences Report &raquo;</a> </li>
21</ol>
22
23</div>
24</div>
25
26
27<p><em>API Level:</em>&nbsp;<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
31downloadable component for the Android SDK. The downloadable platform includes
32an Android library and system image, as well as a set of emulator skins and
33more. The downloadable platform includes no external libraries.</p>
34
35<p>For developers, the Android {@sdkPlatformVersion} platform is available as a
36downloadable component for the Android SDK. The downloadable platform includes
37an Android library and system image, as well as a set of emulator skins and
38more. To get started developing or testing against Android {@sdkPlatformVersion},
39use 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
46in Android 3.1, including new features and changes in the framework API since
47the previous version.</p>
48
49<h3 id="usb">USB APIs</h3>
50
51<p>Android 3.1 introduces powerful new APIs for
52integrating connected peripherals with applications running on the platform.
53The APIs are based on a USB (Universal Serial Bus) stack and services that are
54built into the platform, including support for both USB host and device
55interactions. Using the APIs, developers can create applications that are able to
56discover, communicate with, and manage a variety of device types connected over
57USB. </p>
58
59<p>The stack and APIs distinguish two basic types of USB hardware, based on
60whether the Android-powered device is acting as host or the external hardware
61is acting as host: </p>
62
63<ul>
64<li>A <em>USB device</em> is a piece of connected hardware that depends on the
65Android-powered device to serve as host. For example, most input devices, mice,
66and 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
68host controller, provides power, and is designed to communicate with
69Android-powered devices over USB, A variety of peripherals can connect as
70accessories, from robotics controllers to musical equipment, exercise bicycles,
71and more.</li>
72</ul>
73
74<p>For both types &mdash; USB devices and USB accessories &mdash; the
75platform's USB APIs support discovery by intent broadcast when attached or
76detached, 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
80central class is {@link android.hardware.usb.UsbManager}, which provides
81helper methods for identifying and communicating with
82both 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
84devices or accessories and then communicate with or manage them.
85{@link android.hardware.usb.UsbManager} also declares intent actions that the
86system broadcasts, to announce when a USB device or accessory is attached or
87detached.</p>
88
89<p>Other classes include:</p>
90
91<ul>
92<li>{@link android.hardware.usb.UsbDevice}, a class representing external
93hardware connected as a USB device (with the Android-powered device acting as
94host).</li>
95<li>{@link android.hardware.usb.UsbAccessory}, representing external hardware
96connected as the USB host (with the Android-powered device acting as a USB
97device).</li>
98<li>{@link android.hardware.usb.UsbInterface} and {@link
99android.hardware.usb.UsbEndpoint}, which provide access to standard USB
100interfaces and endpoints for a device.</li>
101<li>{@link android.hardware.usb.UsbDeviceConnection} and {@link
102android.hardware.usb.UsbRequest}, for sending and receiving data and control
103messages to or from a USB device, sychronously and asynchronously.
104<li>{@link android.hardware.usb.UsbConstants}, which provides constants for
105declaring 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
109for USB host and open accessory modes on specific devices is determined by
110their manufacturers. In particular, host mode relies on appropriate USB
111controller hardware in the Android-powered device. </p>
112
113<p>Additionally, developers can request filtering on Google Play, such that
114their applications are not availabe to users whose devices do not provide the
115appropriate USB support. To request filtering, add one or both of the elements
116below to the application manifest, as appropriate: </p>
117
118<ul>
119<li>If the application should only be visible to devices that support USB
120host mode (connection of USB devices), declare this element:
121  <p style="margin-left:1.5em;"><code>&lt;uses-feature
122  android:name="android.hardware.usb.host"
123  android:required="true"&gt;</code></p>
124</li>
125<li>If the application should only be visible to devices that support USB
126accessories (connection of USB hosts), declare this element:
127  <p style="margin-left:1.5em;"><code>&lt;uses-feature
128  android:name="android.hardware.usb.accessory"
129  android:required="true"&gt;</code></p>
130</li>
131</ul>
132
133<p>For complete information about how to develop applications that interact with
134USB 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
138href="{@docRoot}resources/samples/USB/AdbTest/index.html">ADB Test</a> and <a
139href="{@docRoot}resources/samples/USB/MissileLauncher/index.html">Missile
140Launcher</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
145with connected cameras and other PTP devices. The new API makes it easy for an
146application to receive notifications when devices are attached and removed,
147manage files and storage on those devices, and transfer files and metadata to
148and from them. The MTP API implements the PTP (Picture Transfer Protocol) subset
149of the MTP (Media Transfer Protocol) specification.</p>
150
151<p>The MTP API is available in the {@link android.mtp} package and provides
152these classes: </p>
153
154<ul>
155  <li>The {@link android.mtp.MtpDevice} encapsulates an MTP device that is
156connected over the USB host bus. An application can instantiate an object of
157this type and then use its methods to get information about the device and
158objects stored on it, as well as opening the connection and transferring data.
159Some of the methods include:
160    <ul>
161      <li>{@link android.mtp.MtpDevice#getObjectHandles(int, int, int)
162getObjectHandles()} returns a list of handles for all objects on the device that
163match a specified format and parent. To get information about an object, an
164application can pass a handle to {@link android.mtp.MtpDevice#getObjectInfo(int)
165getObjectInfo()}.</li>
166      <li>{@link android.mtp.MtpDevice#importFile(int, java.lang.String)
167importFile()} lets an application copy data for an object to a file in external
168storage. This call may block for an arbitrary amount of time depending on the
169size of the data and speed of the devices, so should be made from a spearate
170thread.</li>
171      <li>{@link
172android.mtp.MtpDevice#open(android.hardware.usb.UsbDeviceConnection) open()}
173lets an application open a connected MTP/PTP device. </li>
174      <li>{@link android.mtp.MtpDevice#getThumbnail(int) getThumbnail()} returns
175the 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
179unit on an MTP device, corresponding to the StorageInfo Dataset described in
180section 5.2.2 of the MTP  specification. Methods in the class let an application
181get a storage unit’s description string, free space, maximum storage capacity,
182storage ID, and volume identifier.</li>
183  <li>{@link android.mtp.MtpDeviceInfo}  holds information about an MTP device
184corresponding to the DeviceInfo Dataset described in section 5.1.1 of the MTP
185specification. Methods in the class let applications get a device’s
186manufacturer, model, serial number, and version.</li>
187  <li>{@link android.mtp.MtpObjectInfo} holds information about an object stored
188on an MTP device, corresponding to the ObjectInfo Dataset described in section
1895.3.1 of the MTP specification. Methods in the class let applications get an
190object’s size, data format, association type, creation date, and thumbnail
191information.</li>
192  <li>{@link android.mtp.MtpConstants} provides constants for declaring MTP file
193format 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
199types of motion events, across all views and windows. Developers can build on
200these capabilities to let users interact with their applications using mice,
201trackballs, joysticks, gamepads, and other devices, in addition to keyboards and
202touchscreens. </p>
203
204<p>For handling mouse, scrollwheel, and trackball input, the platform supports
205two new motion event actions:</p>
206<ul>
207<li>{@link android.view.MotionEvent#ACTION_SCROLL}, which describes the pointer
208location at which a non-touch scroll motion, such as from a mouse scroll wheel,
209took place. In the MotionEvent, the value of the {@link
210android.view.MotionEvent#AXIS_HSCROLL} and {@link
211android.view.MotionEvent#AXIS_VSCROLL} axes specify the relative scroll
212movement. </li>
213<li>{@link android.view.MotionEvent#ACTION_HOVER_MOVE}, reports the current
214position of the mouse when no buttons are pressed, as well as any intermediate
215points since the last <code>HOVER_MOVE</code> event. Hover enter and exit
216notifications are not yet supported.</li>
217</ul>
218
219<p>To support joysticks and gamepads, the {@link android.view.InputDevice} class
220includes these new input device sources:</p>
221<ul>
222<li>{@link android.view.InputDevice#SOURCE_CLASS_JOYSTICK} &mdash; the source
223device has joystick axes.</li>
224<li>{@link android.view.InputDevice#SOURCE_CLASS_BUTTON} &mdash; the source
225device has buttons or keys.</li>
226<li>{@link android.view.InputDevice#SOURCE_GAMEPAD}  &mdash;  the source device
227has gamepad buttons such as {@link android.view.KeyEvent#KEYCODE_BUTTON_A}
228or {@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} &mdash; the source device
231has 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
235and trackballs, the platform now defines axis codes on {@link
236android.view.MotionEvent}, similar to how it defines key codes on {@link
237android.view.KeyEvent}. New axis codes for joysticks
238and game controllers include
239{@link android.view.MotionEvent#AXIS_HAT_X}, {@link
240android.view.MotionEvent#AXIS_HAT_Y}, {@link
241android.view.MotionEvent#AXIS_RTRIGGER}, {@link
242android.view.MotionEvent#AXIS_ORIENTATION}, {@link
243android.view.MotionEvent#AXIS_THROTTLE}, and many others.
244Existing {@link android.view.MotionEvent} axes are represented by {@link
245android.view.MotionEvent#AXIS_X}, {@link android.view.MotionEvent#AXIS_Y},
246{@link android.view.MotionEvent#AXIS_PRESSURE}, {@link
247android.view.MotionEvent#AXIS_SIZE}, {@link
248android.view.MotionEvent#AXIS_TOUCH_MAJOR}, {@link
249android.view.MotionEvent#AXIS_TOUCH_MINOR}, {@link
250android.view.MotionEvent#AXIS_TOOL_MAJOR}, {@link
251android.view.MotionEvent#AXIS_TOOL_MINOR}, and {@link
252android.view.MotionEvent#AXIS_ORIENTATION}.</p>
253
254<p>Additionally, {@link android.view.MotionEvent} defines a number of generic
255axis codes that are used when the framework does not know how to map a
256particular axis. Specific devices can use the generic axis codes to pass custom
257motion data to applications. For a full list of axes and their intended
258interpretations, 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
262event may contain a current position and multiple so-called historical movements.
263Applications should use {@link android.view.MotionEvent#getHistorySize()} to get
264the number of historical samples, then retrieve and process all historical
265samples in order using {@link
266android.view.MotionEvent#getHistoricalAxisValue(int, int, int)
267getHistoricalAxisValue()}.  After that, applications should process the current
268sample using {@link android.view.MotionEvent#getAxisValue(int) getAxisValue()}.
269</p>
270
271<p>Some axes can be retrieved using special accessor methods.  For example,
272instead of calling {@link android.view.MotionEvent#getAxisValue(int)
273getAxisValue()}, applications can call {@link android.view.MotionEvent#getX(int)
274getX()}.  Axes that have built-in accessors include {@link
275android.view.MotionEvent#AXIS_X}, {@link android.view.MotionEvent#AXIS_Y},
276{@link android.view.MotionEvent#AXIS_PRESSURE}, {@link
277android.view.MotionEvent#AXIS_SIZE}, {@link
278android.view.MotionEvent#AXIS_TOUCH_MAJOR}, {@link
279android.view.MotionEvent#AXIS_TOUCH_MINOR}, {@link
280android.view.MotionEvent#AXIS_TOOL_MAJOR}, {@link
281android.view.MotionEvent#AXIS_TOOL_MINOR}, and {@link
282android.view.MotionEvent#AXIS_ORIENTATION}.</p>
283
284<p>Each input device has a unique, system-assigned ID and may also provide
285multiple sources. When a device provides multiple sources, more than one source
286can provide axis data using the same axis. For example, a touch event coming
287from the touch source uses the X axis for screen position data, while a joystick
288event coming from the joystick source will use the X axis for the stick position
289instead. For this reason, it's important for applications to interpret axis
290values according to the source from which they originate. When handling a motion
291event, applications should use methods on the {@link android.view.InputDevice}
292class to determine the axes supported by a device or source. Specifically,
293applications can use {@link android.view.InputDevice#getMotionRanges()
294getMotionRanges()} to query for all axes of a device or all axes of a given
295source of the device. In both cases, the range information for axes returned in
296the {@link android.view.InputDevice.MotionRange} object specifies the source for
297each axis value.</p>
298
299<p>Finally, since the motion events from joysticks, gamepads, mice, and
300trackballs are not touch events, the platform adds a new callback method for
301passing them to a {@link android.view.View} as "generic" motion events.
302Specifically, it reports the non-touch motion events to
303{@link android.view.View}s through a call to {@link
304android.view.View#onGenericMotionEvent(android.view.MotionEvent)
305onGenericMotionEvent()}, rather than to {@link
306android.view.View#onTouchEvent(android.view.MotionEvent)
307onTouchEvent()}.</p>
308
309<p>The platform dispatches generic motion events differently, depending on the
310event source class. {@link android.view.InputDevice#SOURCE_CLASS_POINTER} events
311go to the {@link android.view.View} under the pointer, similar to how touch
312events work.  All others go to the currently focused {@link android.view.View}.
313For example, this means a {@link android.view.View} must take focus in order to
314receive joystick events. If needed, applications can handle these events at the
315level of Activity or Dialog by implementing {@link
316android.view.View#onGenericMotionEvent(android.view.MotionEvent)
317onGenericMotionEvent()} there instead.</p>
318
319<p class="note">To look at a sample application that uses joystick motion
320events, see <a
321href="{@docRoot}resources/samples/ApiDemos/src/com/example/android/apis/view/GameControllerInput.html">GameControllerInput</a>
322and <a
323href="{@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)
328stack, which applications can use to manage on-demand or interactive data
329streaming. In particular, apps that provide VOIP, push-to-talk, conferencing,
330and audio streaming can use the API to initiate sessions and transmit or receive
331data streams over any available network.</p>
332
333<p>The RTP API is available in the {@link android.net.rtp} package. Classes
334include: </p>
335<ul>
336<li>{@link android.net.rtp.RtpStream}, the base class of streams that send and
337receive network packets with media payloads over RTP.</li>
338<li>{@link android.net.rtp.AudioStream}, a subclass of {@link
339android.net.rtp.RtpStream} that carries audio payloads over RTP.</li>
340<li>{@link android.net.rtp.AudioGroup}, a local audio hub for managing and
341mixing 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
343you define for an {@link android.net.rtp.AudioStream}.</li>
344</ul>
345
346<p>To support audio conferencing and similar usages, an application instantiates
347two classes as endpoints for the stream:</p>
348
349<ul>
350<li>{@link android.net.rtp.AudioStream} specifies a remote endpoint and consists
351of network mapping and a configured {@link android.net.rtp.AudioCodec}.</li>
352<li>{@link android.net.rtp.AudioGroup} represents the local endpoint for one
353or more {@link android.net.rtp.AudioStream}s. The {@link android.net.rtp.AudioGroup} mixes
354all the {@link android.net.rtp.AudioStream}s and optionally interacts with the device
355speaker and the microphone at the same time.</li>
356</ul>
357
358<p>The simplest usage involves a single remote endpoint and local endpoint.
359For 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
363declaring <code>&lt;uses-permission
364android:name="android.permission.INTERNET"&gt;</code>
365in their manifest files. To acquire the device microphone, the <code>&lt;uses-permission
366android:name="android.permission.RECORD_AUDIO"&gt;</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
371resizeable &mdash; horizontally, vertically, or on both axes. Users touch-hold a
372widget to show its resize handles, then drag the horizontal and/or vertical
373handles 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
377android.appwidget.AppWidgetProviderInfo} metadata. Values for the
378<code>resizeMode</code> attribute include "horizontal", "vertical", and "none".
379To 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>&lt;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" &gt;
392&lt;/appwidget-provider&gt;</pre>
393
394<p>For more information about Home screen widgets, see the <a
395href="{@docRoot}guide/topics/appwidgets/index.html">App Widgets</a>
396documentation.</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
404convenient
405way for developers to animate select properties on {@link android.view.View} objects. The class
406automaties and optimizes the animation of the properties and makes it easier to
407manage multiple simulataneous animations on a {@link android.view.View} object.
408<p>Using the {@link android.view.ViewPropertyAnimator} is straightforward. To animate properties for
409a {@link android.view.View}, call {@link android.view.View#animate()} to
410construct a {@link android.view.ViewPropertyAnimator} object for that {@link android.view.View}. Use the
411methods on the {@link android.view.ViewPropertyAnimator} to specify what property to
412animate and how to animate it. For example, to fade the {@link android.view.View} to transparent,
413call <code>alpha(0);</code>. The {@link android.view.ViewPropertyAnimator} object
414handles the details of configuring the underlying {@link
415android.animation.Animator} class and starting it, then rendering the
416animation.</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
424only. 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()}
430method
431lets you get the current animation fraction &mdash; the elapsed/interpolated
432fraction used in the most recent frame update &mdash; from a {@link
433android.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
443force a View's layer to be created and the View rendered into it immediately.
444For example, an application could use this method to render a View into its
445layer before starting an animation. If the View is complex, rendering it into
446the 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
453camera
454to a View. This gives applications improved control over 3D transformations of
455the 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
462android.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
469receive
470callbacks when a View is attached or detached from its window. Use {@link
471android.view.View#addOnAttachStateChangeListener(android.view.View.OnAttachStateChangeListener) addOnAttachStateChangeListener()}
472to add a listener and {@link
473android.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
479android.app.FragmentBreadCrumbs#setOnBreadCrumbClickListener(android.app.FragmentBreadCrumbs.OnBreadCrumbClickListener) setOnBreadCrumbClickListener()},
480provides a hook to let
481applications intercept fragment-breadcrumb clicks and take any action needed
482before going to the backstack entry or fragment that was clicked. </li>
483    <li>In the {@link android.app.Fragment} class, {@link
484android.app.Fragment#onInflate(android.util.AttributeSet, android.os.Bundle)
485onInflate(attrs, savedInstanceState)} is deprecated. Please use {@link
486android.app.Fragment#onInflate(android.app.Activity, android.util.AttributeSet,
487android.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
493android.content.Intent#ACTION_WEB_SEARCH} intents lets you open a search in a
494new 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
501resource 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
507android.widget.RemoteViews#setDisplayedChild(int, int) setDisplayedChild(viewId,
508childIndex)}, is available in {@link android.widget.RemoteViews} subclasses, to
509let you set the child displayed in {@link android.widget.ViewAnimator} and
510{@link android.widget.AdapterViewAnimator} subclasses such as {@link
511android.widget.AdapterViewFlipper}, {@link android.widget.StackView}, {@link
512android.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
531all of the pixels in a Bitmap are known to be opaque (false) or that some of the
532pixels may contain non-opaque alpha values (true). Note, for some configs (such
533as RGB_565) this call is ignored, since it does not support per-pixel alpha
534values. This is meant as a drawing hint, as in some cases a bitmap that is known
535to be opaque can take a faster drawing case than one that may have non-opaque
536per-pixel alpha values. </li>
537  <li>{@link android.graphics.Bitmap#getByteCount()} gets a Bitmap's size in
538bytes.</li>
539  <li>{@link android.graphics.Bitmap#getGenerationId()} lets an application find
540out whether a Bitmap has been modified, such as for caching.</li>
541  <li>{@link android.graphics.Bitmap#sameAs(android.graphics.Bitmap)} determines
542whether a given Bitmap differs from the current Bitmap, in dimension,
543configuration, 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
549android.graphics.Camera#rotate(float, float, float) rotate()} and {@link
550android.graphics.Camera#setLocation(float, float, float) setLocation()} for
551control of the
552camera'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
563high-performance Wi-Fi connections even when the device screen is off.
564Applications that stream music, video, or voice for long periods can acquire the
565high-performance Wi-Fi lock to ensure streaming performance even when the screen
566is off. Because it uses more power, applications should acquire the
567high-performance Wi-Fi when there is a need for a long-running active
568connection.
569<p>To create a high-performance lock, pass {@link
570android.net.wifi.WifiManager#WIFI_MODE_FULL_HIGH_PERF} as the lock mode in a
571call to {@link android.net.wifi.WifiManager#createWifiLock(int,
572java.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
578using new methods in {@link android.net.TrafficStats}. Applications can use the
579methods to get UDP stats, packet count, TCP transmit/receive payload bytes and
580segments 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
586using
587the new methods {@link android.net.sip.SipProfile#getAuthUserName()
588getAuthUserName()} and {@link
589android.net.sip.SipProfile.Builder#setAuthUserName(java.lang.String)
590setAuthUserName()}.</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
601completion. To initiate this type of download, applications pass {@link
602android.app.DownloadManager.Request#VISIBILITY_VISIBLE_NOTIFY_ONLY_COMPLETION}
603in the {@link
604android.app.DownloadManager.Request#setNotificationVisibility(int)
605setNotificationVisibility()} method of
606the a request object.</li>
607    <li>A new method, {@link
608android.app.DownloadManager#addCompletedDownload(java.lang.String,
609java.lang.String, boolean, java.lang.String, java.lang.String, long, boolean)
610addCompletedDownload()}, lets an application add a file to the
611downloads 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
617adding the new extra {@link
618android.app.DownloadManager#INTENT_EXTRAS_SORT_BY_SIZE} to an {@link
619android.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
629method
630{@link
631android.view.inputmethod.InputMethodSubtype#containsExtraValueKey(java.lang.String) containsExtraValueKey()} to check whether an ExtraValue string is stored
632for the subtype and
633the method {@link
634android.view.inputmethod.InputMethodSubtype#getExtraValueOf(java.lang.String)
635getExtraValueOf()} 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
647improved streaming audio, as well as support for FLAC audio, for highest quality
648(lossless) compressed audio content. See the <a
649href="{@docRoot}guide/appendix/media-formats.html">Supported Media Formats</a>
650document 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
656applications</h3>
657
658<p>Starting from Android 3.1, the system's package manager keeps track of
659applications that are in a stopped state and provides a means of controlling
660their 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
663stopped 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
666whether the Intent should be allowed to activate components in stopped
667application.</p>
668
669<ul>
670<li>{@link android.content.Intent#FLAG_INCLUDE_STOPPED_PACKAGES} &mdash;
671Include intent filters of stopped applications in the list of potential targets
672to resolve against. </li>
673<li>{@link android.content.Intent#FLAG_EXCLUDE_STOPPED_PACKAGES} &mdash;
674Exclude intent filters of stopped applications from the list of potential
675targets.</li>
676</ul>
677
678<p>When neither or both of these flags is defined in an intent, the default
679behavior is to include filters of stopped applications in the list of
680potential targets.</p>
681
682<p>Note that the system adds {@link
683android.content.Intent#FLAG_EXCLUDE_STOPPED_PACKAGES} <em>to all broadcast
684intents</em>. It does this to prevent broadcasts from background services from
685inadvertently or unnecessarily launching components of stoppped applications.
686A background service or application can override this behavior by adding the
687{@link android.content.Intent#FLAG_INCLUDE_STOPPED_PACKAGES} flag to broadcast
688intents 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
691yet launched and when they are manually stopped by the user (in Manage
692Applications).</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
697upgrades through two new intent actions:</p>
698
699<ul>
700<li>{@link android.content.Intent#ACTION_PACKAGE_FIRST_LAUNCH} &mdash; Sent to
701the 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
703contains the name of the package. </li>
704
705<li>{@link android.content.Intent#ACTION_MY_PACKAGE_REPLACED} &mdash; Notifies
706an application that it was updated, with a new version was installed over
707an existing version.  This is only sent to the application that was replaced. It
708does not contain any additional data. To receive it, declare an intent filter
709for this action. You can use the intent to trigger code that helps get your
710application back in proper running shape after an upgrade.
711
712<p>This intent is sent directly to the application, but only if the application
713was 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
723from efficient caching. Applications can use the class to reduce the time spent
724computing or downloading data from the network, while maintaining a sensible
725memory footprint for the cached data.{@link android.util.LruCache} is a cache
726that holds strong references to a limited number of values. Each time a value is
727accessed, it is moved to the head of a queue. When a value is added to a full
728cache, the value at the end of that queue is evicted and may become eligible for
729garbage 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
735android.os.ParcelFileDescriptor} using either of the new methods {@link
736android.os.ParcelFileDescriptor#getFd()} or {@link
737android.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
754the
755<code>file:</code> URI scheme. You can use {@link
756android.webkit.CookieManager#setAcceptFileSchemeCookies(boolean)
757setAcceptFileSchemeCookies()} to
758enable/disable support for file scheme cookies, before constructing an instance
759of <code>WebView</code> or <code>CookieManager</code>. In a
760<code>CookieManager</code> instance, you can check whether file scheme cookies
761is enabled by calling {@link
762android.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
768new
769method {@link
770android.webkit.WebViewClient#onReceivedLoginRequest(android.webkit.WebView,java.lang.String, java.lang.String, java.lang.String) onReceivedLoginRequest()}
771notifies the host
772application 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
778previously being in deprecated state. See the <a
779href="{@docRoot}sdk/api_diff/{@sdkPlatformApiLevel}/changes.html">API
780Differences 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
790applications:</p>
791
792<ul>
793<li>Support for inline playback of video embedded in HTML5
794<code>&lt;video&gt;</code> tag. Playback is hardware-accelerated where possible.
795</li>
796<li>Layer support for fixed position elements for all sites (mobile and
797desktop).</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
807in their application manifests, to inform external entities such as Google
808Play of the application's requirement for new hardware capabilities supported
809in this version of the platform. Developers declare these and other feature
810constants in <a
811href="{@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
816android.hardware.usb.accessory} &mdash; The application uses the <a href="#usb">USB
817API</a> to communicate with external hardware devices connected over USB and
818function as hosts.</li>
819  <li>{@link android.content.pm.PackageManager#FEATURE_USB_HOST
820android.hardware.usb.host} &mdash; The application uses the <a href="#usb">USB API</a>
821to communicate with external hardware devices connected over USB and function as
822devices.</li>
823</ul>
824
825<p>Google Play filters applications based on features declared in <a
826href="{@docRoot}guide/topics/manifest/uses-feature-element.html">{@code
827<uses-feature>}</a> manifest elements. For more information about
828declaring features in an application manifest, read <a
829href="{@docRoot}google/play/filters.html">Google Play
830Filters</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
837Level
838{@sdkPlatformApiLevel}), see the <a
839href="{@docRoot}sdk/api_diff/{@sdkPlatformApiLevel}/changes.html">API
840Differences 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
849the framework API. The Android {@sdkPlatformVersion} API
850is assigned an integer identifier &mdash;
851<strong>{@sdkPlatformApiLevel}</strong> &mdash; that is
852stored in the system itself. This identifier, called the "API Level", allows the
853system to correctly determine whether an application is compatible with
854the system, prior to installing the application. </p>
855
856<p>To use APIs introduced in Android {@sdkPlatformVersion} in your application,
857you need compile the application against the Android library that is provided in
858the Android {@sdkPlatformVersion} SDK platform. Depending on your needs, you
859might
860also need to add an <code>android:minSdkVersion="{@sdkPlatformApiLevel}"</code>
861attribute to the <code>&lt;uses-sdk&gt;</code> element in the application's
862manifest.</p>
863
864<p>For more information, read <a href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#ApiLevels">What is API
865Level?</a></p>
866