*API Level:* **12**

For developers, the Android 3.1 platform ([HONEYCOMB_MR1](https://developer.android.com/reference/android/os/Build.VERSION_CODES#HONEYCOMB_MR1)) is available as a downloadable component for the Android SDK. The downloadable platform includes an Android library and system image, as well as a set of emulator skins and more. The downloadable platform includes no external libraries.

For developers, the Android 3.1 platform is available as a downloadable component for the Android SDK. The downloadable platform includes an Android library and system image, as well as a set of emulator skins and more. To get started developing or testing against Android 3.1, use the Android SDK Manager to download the platform into your SDK.

## API Overview

The sections below provide a technical overview of what's new for developers in Android 3.1, including new features and changes in the framework API since the previous version.

### USB APIs

Android 3.1 introduces powerful new APIs for integrating connected peripherals with applications running on the platform. The APIs are based on a USB (Universal Serial Bus) stack and services that are built into the platform, including support for both USB host and device interactions. Using the APIs, developers can create applications that are able to discover, communicate with, and manage a variety of device types connected over USB.

The stack and APIs distinguish two basic types of USB hardware, based on whether the Android-powered device is acting as host or the external hardware is acting as host:

- A*USB device*is a piece of connected hardware that depends on the Android-powered device to serve as host. For example, most input devices, mice, and joysticks are USB devices, as are many cameras, hubs, and so on.
- A*USB accessory*is a piece of connected hardware that has a USB host controller, provides power, and is designed to communicate with Android-powered devices over USB, A variety of peripherals can connect as accessories, from robotics controllers to musical equipment, exercise bicycles, and more.

For both types --- USB devices and USB accessories --- the platform's USB APIs support discovery by intent broadcast when attached or detached, as well as standard interfaces, endpoints, and transfer modes (control, bulk, and interrupt).

The USB APIs are available in the package[android.hardware.usb](https://developer.android.com/reference/android/hardware/usb/package-summary). The central class is[UsbManager](https://developer.android.com/reference/android/hardware/usb/UsbManager), which provides helper methods for identifying and communicating with both USB devices and USB accessories. Applications can acquire an instance of[UsbManager](https://developer.android.com/reference/android/hardware/usb/UsbManager)and then query for the list of attached devices or accessories and then communicate with or manage them.[UsbManager](https://developer.android.com/reference/android/hardware/usb/UsbManager)also declares intent actions that the system broadcasts, to announce when a USB device or accessory is attached or detached.

Other classes include:

- [UsbDevice](https://developer.android.com/reference/android/hardware/usb/UsbDevice), a class representing external hardware connected as a USB device (with the Android-powered device acting as host).
- [UsbAccessory](https://developer.android.com/reference/android/hardware/usb/UsbAccessory), representing external hardware connected as the USB host (with the Android-powered device acting as a USB device).
- [UsbInterface](https://developer.android.com/reference/android/hardware/usb/UsbInterface)and[UsbEndpoint](https://developer.android.com/reference/android/hardware/usb/UsbEndpoint), which provide access to standard USB interfaces and endpoints for a device.
- [UsbDeviceConnection](https://developer.android.com/reference/android/hardware/usb/UsbDeviceConnection)and[UsbRequest](https://developer.android.com/reference/android/hardware/usb/UsbRequest), for sending and receiving data and control messages to or from a USB device, synchronously and asynchronously.
- [UsbConstants](https://developer.android.com/reference/android/hardware/usb/UsbConstants), which provides constants for declaring endpoint types, device classes, and so on.

Note that although the USB stack is built into the platform, actual support for USB host and open accessory modes on specific devices is determined by their manufacturers. In particular, host mode relies on appropriate USB controller hardware in the Android-powered device.

Additionally, developers can request filtering on Google Play, such that their applications are not available to users whose devices do not provide the appropriate USB support. To request filtering, add one or both of the elements below to the application manifest, as appropriate:

- If the application should only be visible to devices that support USB host mode (connection of USB devices), declare this element:`<uses-feature
  android:name="android.hardware.usb.host"
  android:required="true">`

- If the application should only be visible to devices that support USB accessories (connection of USB hosts), declare this element:`<uses-feature
  android:name="android.hardware.usb.accessory"
  android:required="true">`

For complete information about how to develop applications that interact with USB accessories, please see the[developer documentation](https://developer.android.com/guide/topics/connectivity/usb).

To look at sample applications that use the USB host API, see[ADB Test](https://developer.android.com/resources/samples/USB/AdbTest)and[Missile Launcher](https://developer.android.com/resources/samples/USB/MissileLauncher)

### MTP/PTP API

Android 3.1 exposes a new MTP API that lets applications interact directly with connected cameras and other PTP devices. The new API makes it easy for an application to receive notifications when devices are attached and removed, manage files and storage on those devices, and transfer files and metadata to and from them. The MTP API implements the PTP (Picture Transfer Protocol) subset of the MTP (Media Transfer Protocol) specification.

The MTP API is available in the[android.mtp](https://developer.android.com/reference/android/mtp/package-summary)package and provides these classes:

- The[MtpDevice](https://developer.android.com/reference/android/mtp/MtpDevice)encapsulates an MTP device that is connected over the USB host bus. An application can instantiate an object of this type and then use its methods to get information about the device and objects stored on it, as well as opening the connection and transferring data. Some of the methods include:
  - [getObjectHandles()](https://developer.android.com/reference/android/mtp/MtpDevice#getObjectHandles(int, int, int))returns a list of handles for all objects on the device that match a specified format and parent. To get information about an object, an application can pass a handle to[getObjectInfo()](https://developer.android.com/reference/android/mtp/MtpDevice#getObjectInfo(int)).
  - [importFile()](https://developer.android.com/reference/android/mtp/MtpDevice#importFile(int, java.lang.String))lets an application copy data for an object to a file in external storage. This call may block for an arbitrary amount of time depending on the size of the data and speed of the devices, so should be made from a spearate thread.
  - [open()](https://developer.android.com/reference/android/mtp/MtpDevice#open(android.hardware.usb.UsbDeviceConnection))lets an application open a connected MTP/PTP device.
  - [getThumbnail()](https://developer.android.com/reference/android/mtp/MtpDevice#getThumbnail(int))returns the thumbnail of the object as a byte array.
- [MtpStorageInfo](https://developer.android.com/reference/android/mtp/MtpStorageInfo)holds information about about a storage unit on an MTP device, corresponding to the StorageInfo Dataset described in section 5.2.2 of the MTP specification. Methods in the class let an application get a storage unit's description string, free space, maximum storage capacity, storage ID, and volume identifier.
- [MtpDeviceInfo](https://developer.android.com/reference/android/mtp/MtpDeviceInfo)holds information about an MTP device corresponding to the DeviceInfo Dataset described in section 5.1.1 of the MTP specification. Methods in the class let applications get a device's manufacturer, model, serial number, and version.
- [MtpObjectInfo](https://developer.android.com/reference/android/mtp/MtpObjectInfo)holds information about an object stored on an MTP device, corresponding to the ObjectInfo Dataset described in section 5.3.1 of the MTP specification. Methods in the class let applications get an object's size, data format, association type, creation date, and thumbnail information.
- [MtpConstants](https://developer.android.com/reference/android/mtp/MtpConstants)provides constants for declaring MTP file format codes, association type, and protection status.

### Support for new input devices and motion events

Android 3.1 extends the input subsystem to support new input devices and new types of motion events, across all views and windows. Developers can build on these capabilities to let users interact with their applications using mice, trackballs, joysticks, gamepads, and other devices, in addition to keyboards and touchscreens.

For handling mouse, scrollwheel, and trackball input, the platform supports two new motion event actions:

- [ACTION_SCROLL](https://developer.android.com/reference/android/view/MotionEvent#ACTION_SCROLL), which describes the pointer location at which a non-touch scroll motion, such as from a mouse scroll wheel, took place. In the MotionEvent, the value of the[AXIS_HSCROLL](https://developer.android.com/reference/android/view/MotionEvent#AXIS_HSCROLL)and[AXIS_VSCROLL](https://developer.android.com/reference/android/view/MotionEvent#AXIS_VSCROLL)axes specify the relative scroll movement.
- [ACTION_HOVER_MOVE](https://developer.android.com/reference/android/view/MotionEvent#ACTION_HOVER_MOVE), reports the current position of the mouse when no buttons are pressed, as well as any intermediate points since the last`HOVER_MOVE`event. Hover enter and exit notifications are not yet supported.

To support joysticks and gamepads, the[InputDevice](https://developer.android.com/reference/android/view/InputDevice)class includes these new input device sources:

- [SOURCE_CLASS_JOYSTICK](https://developer.android.com/reference/android/view/InputDevice#SOURCE_CLASS_JOYSTICK)--- the source device has joystick axes.
- [SOURCE_CLASS_BUTTON](https://developer.android.com/reference/android/view/InputDevice#SOURCE_CLASS_BUTTON)--- the source device has buttons or keys.
- [SOURCE_GAMEPAD](https://developer.android.com/reference/android/view/InputDevice#SOURCE_GAMEPAD)--- the source device has gamepad buttons such as[KEYCODE_BUTTON_A](https://developer.android.com/reference/android/view/KeyEvent#KEYCODE_BUTTON_A)or[KEYCODE_BUTTON_B](https://developer.android.com/reference/android/view/KeyEvent#KEYCODE_BUTTON_B). Implies[SOURCE_CLASS_BUTTON](https://developer.android.com/reference/android/view/InputDevice#SOURCE_CLASS_BUTTON)
- [SOURCE_JOYSTICK](https://developer.android.com/reference/android/view/InputDevice#SOURCE_JOYSTICK)--- the source device has joystick axes. Implies SOURCE_CLASS_JOYSTICK.

To describe motion events from these new sources, as well as those from mice and trackballs, the platform now defines axis codes on[MotionEvent](https://developer.android.com/reference/android/view/MotionEvent), similar to how it defines key codes on[KeyEvent](https://developer.android.com/reference/android/view/KeyEvent). New axis codes for joysticks and game controllers include[AXIS_HAT_X](https://developer.android.com/reference/android/view/MotionEvent#AXIS_HAT_X),[AXIS_HAT_Y](https://developer.android.com/reference/android/view/MotionEvent#AXIS_HAT_Y),[AXIS_RTRIGGER](https://developer.android.com/reference/android/view/MotionEvent#AXIS_RTRIGGER),[AXIS_ORIENTATION](https://developer.android.com/reference/android/view/MotionEvent#AXIS_ORIENTATION),[AXIS_THROTTLE](https://developer.android.com/reference/android/view/MotionEvent#AXIS_THROTTLE), and many others. Existing[MotionEvent](https://developer.android.com/reference/android/view/MotionEvent)axes are represented by[AXIS_X](https://developer.android.com/reference/android/view/MotionEvent#AXIS_X),[AXIS_Y](https://developer.android.com/reference/android/view/MotionEvent#AXIS_Y),[AXIS_PRESSURE](https://developer.android.com/reference/android/view/MotionEvent#AXIS_PRESSURE),[AXIS_SIZE](https://developer.android.com/reference/android/view/MotionEvent#AXIS_SIZE),[AXIS_TOUCH_MAJOR](https://developer.android.com/reference/android/view/MotionEvent#AXIS_TOUCH_MAJOR),[AXIS_TOUCH_MINOR](https://developer.android.com/reference/android/view/MotionEvent#AXIS_TOUCH_MINOR),[AXIS_TOOL_MAJOR](https://developer.android.com/reference/android/view/MotionEvent#AXIS_TOOL_MAJOR),[AXIS_TOOL_MINOR](https://developer.android.com/reference/android/view/MotionEvent#AXIS_TOOL_MINOR), and[AXIS_ORIENTATION](https://developer.android.com/reference/android/view/MotionEvent#AXIS_ORIENTATION).

Additionally,[MotionEvent](https://developer.android.com/reference/android/view/MotionEvent)defines a number of generic axis codes that are used when the framework does not know how to map a particular axis. Specific devices can use the generic axis codes to pass custom motion data to applications. For a full list of axes and their intended interpretations, see the[MotionEvent](https://developer.android.com/reference/android/view/MotionEvent)class documentation.

The platform provides motion events to applications in batches, so a single event may contain a current position and multiple so-called historical movements. Applications should use[getHistorySize()](https://developer.android.com/reference/android/view/MotionEvent#getHistorySize())to get the number of historical samples, then retrieve and process all historical samples in order using[getHistoricalAxisValue()](https://developer.android.com/reference/android/view/MotionEvent#getHistoricalAxisValue(int, int, int)). After that, applications should process the current sample using[getAxisValue()](https://developer.android.com/reference/android/view/MotionEvent#getAxisValue(int)).

Some axes can be retrieved using special accessor methods. For example, instead of calling[getAxisValue()](https://developer.android.com/reference/android/view/MotionEvent#getAxisValue(int)), applications can call[getX()](https://developer.android.com/reference/android/view/MotionEvent#getX(int)). Axes that have built-in accessors include[AXIS_X](https://developer.android.com/reference/android/view/MotionEvent#AXIS_X),[AXIS_Y](https://developer.android.com/reference/android/view/MotionEvent#AXIS_Y),[AXIS_PRESSURE](https://developer.android.com/reference/android/view/MotionEvent#AXIS_PRESSURE),[AXIS_SIZE](https://developer.android.com/reference/android/view/MotionEvent#AXIS_SIZE),[AXIS_TOUCH_MAJOR](https://developer.android.com/reference/android/view/MotionEvent#AXIS_TOUCH_MAJOR),[AXIS_TOUCH_MINOR](https://developer.android.com/reference/android/view/MotionEvent#AXIS_TOUCH_MINOR),[AXIS_TOOL_MAJOR](https://developer.android.com/reference/android/view/MotionEvent#AXIS_TOOL_MAJOR),[AXIS_TOOL_MINOR](https://developer.android.com/reference/android/view/MotionEvent#AXIS_TOOL_MINOR), and[AXIS_ORIENTATION](https://developer.android.com/reference/android/view/MotionEvent#AXIS_ORIENTATION).

Each input device has a unique, system-assigned ID and may also provide multiple sources. When a device provides multiple sources, more than one source can provide axis data using the same axis. For example, a touch event coming from the touch source uses the X axis for screen position data, while a joystick event coming from the joystick source will use the X axis for the stick position instead. For this reason, it's important for applications to interpret axis values according to the source from which they originate. When handling a motion event, applications should use methods on the[InputDevice](https://developer.android.com/reference/android/view/InputDevice)class to determine the axes supported by a device or source. Specifically, applications can use[getMotionRanges()](https://developer.android.com/reference/android/view/InputDevice#getMotionRanges())to query for all axes of a device or all axes of a given source of the device. In both cases, the range information for axes returned in the[InputDevice.MotionRange](https://developer.android.com/reference/android/view/InputDevice.MotionRange)object specifies the source for each axis value.

Finally, since the motion events from joysticks, gamepads, mice, and trackballs are not touch events, the platform adds a new callback method for passing them to a[View](https://developer.android.com/reference/android/view/View)as "generic" motion events. Specifically, it reports the non-touch motion events to[View](https://developer.android.com/reference/android/view/View)s through a call to[onGenericMotionEvent()](https://developer.android.com/reference/android/view/View#onGenericMotionEvent(android.view.MotionEvent)), rather than to[onTouchEvent()](https://developer.android.com/reference/android/view/View#onTouchEvent(android.view.MotionEvent)).

The platform dispatches generic motion events differently, depending on the event source class.[SOURCE_CLASS_POINTER](https://developer.android.com/reference/android/view/InputDevice#SOURCE_CLASS_POINTER)events go to the[View](https://developer.android.com/reference/android/view/View)under the pointer, similar to how touch events work. All others go to the currently focused[View](https://developer.android.com/reference/android/view/View). For example, this means a[View](https://developer.android.com/reference/android/view/View)must take focus in order to receive joystick events. If needed, applications can handle these events at the level of Activity or Dialog by implementing[onGenericMotionEvent()](https://developer.android.com/reference/android/view/View#onGenericMotionEvent(android.view.MotionEvent))there instead.

To look at a sample application that uses joystick motion events, see[GameControllerInput](https://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/GameControllerInput)and[GameView](https://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/GameView).

### RTP API

Android 3.1 exposes an API to its built-in RTP (Real-time Transport Protocol) stack, which applications can use to manage on-demand or interactive data streaming. In particular, apps that provide VOIP, push-to-talk, conferencing, and audio streaming can use the API to initiate sessions and transmit or receive data streams over any available network.

The RTP API is available in the[android.net.rtp](https://developer.android.com/reference/android/net/rtp/package-summary)package. Classes include:

- [RtpStream](https://developer.android.com/reference/android/net/rtp/RtpStream), the base class of streams that send and receive network packets with media payloads over RTP.
- [AudioStream](https://developer.android.com/reference/android/net/rtp/AudioStream), a subclass of[RtpStream](https://developer.android.com/reference/android/net/rtp/RtpStream)that carries audio payloads over RTP.
- [AudioGroup](https://developer.android.com/reference/android/net/rtp/AudioGroup), a local audio hub for managing and mixing the device speaker, microphone, and[AudioStream](https://developer.android.com/reference/android/net/rtp/AudioStream).
- [AudioCodec](https://developer.android.com/reference/android/net/rtp/AudioCodec), which holds a collection of codecs that you define for an[AudioStream](https://developer.android.com/reference/android/net/rtp/AudioStream).

To support audio conferencing and similar usages, an application instantiates two classes as endpoints for the stream:

- [AudioStream](https://developer.android.com/reference/android/net/rtp/AudioStream)specifies a remote endpoint and consists of network mapping and a configured[AudioCodec](https://developer.android.com/reference/android/net/rtp/AudioCodec).
- [AudioGroup](https://developer.android.com/reference/android/net/rtp/AudioGroup)represents the local endpoint for one or more[AudioStream](https://developer.android.com/reference/android/net/rtp/AudioStream)s. The[AudioGroup](https://developer.android.com/reference/android/net/rtp/AudioGroup)mixes all the[AudioStream](https://developer.android.com/reference/android/net/rtp/AudioStream)s and optionally interacts with the device speaker and the microphone at the same time.

The simplest usage involves a single remote endpoint and local endpoint. For more complex usages, please refer to the limitations described for[AudioGroup](https://developer.android.com/reference/android/net/rtp/AudioGroup).

To use the RTP API, applications must request permission from the user by declaring`<uses-permission
android:name="android.permission.INTERNET">`in their manifest files. To acquire the device microphone, the`<uses-permission
android:name="android.permission.RECORD_AUDIO">`permission is also required.

### Resizable app widgets

Starting in Android 3.1, developers can make their homescreen widgets resizeable --- horizontally, vertically, or on both axes. Users touch-hold a widget to show its resize handles, then drag the horizontal and/or vertical handles to change the size on the layout grid.

Developers can make any Home screen widget resizeable by defining a`resizeMode`attribute in the widget's[AppWidgetProviderInfo](https://developer.android.com/reference/android/appwidget/AppWidgetProviderInfo)metadata. Values for the`resizeMode`attribute include "horizontal", "vertical", and "none". To declare a widget as resizeable horizontally and vertically, supply the value "horizontal\|vertical".

Here's an example:  

```transact-sql
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
    android:minWidth="294dp"
    android:minHeight="72dp"
    android:updatePeriodMillis="86400000"
    android:previewImage="@drawable/preview"
    android:initialLayout="@layout/example_appwidget"
    android:configure="com.example.android.ExampleAppWidgetConfigure"
    android:resizeMode="horizontal|vertical" >
</appwidget-provider>
```

For more information about Home screen widgets, see the[App Widgets](https://developer.android.com/guide/topics/appwidgets)documentation.

### Animation framework

- New ViewPropertyAnimator class
  - A new[ViewPropertyAnimator](https://developer.android.com/reference/android/view/ViewPropertyAnimator)class provides a convenient way for developers to animate select properties on[View](https://developer.android.com/reference/android/view/View)objects. The class automaties and optimizes the animation of the properties and makes it easier to manage multiple simultaneous animations on a[View](https://developer.android.com/reference/android/view/View)object.

    Using the[ViewPropertyAnimator](https://developer.android.com/reference/android/view/ViewPropertyAnimator)is straightforward. To animate properties for a[View](https://developer.android.com/reference/android/view/View), call[animate()](https://developer.android.com/reference/android/view/View#animate())to construct a[ViewPropertyAnimator](https://developer.android.com/reference/android/view/ViewPropertyAnimator)object for that[View](https://developer.android.com/reference/android/view/View). Use the methods on the[ViewPropertyAnimator](https://developer.android.com/reference/android/view/ViewPropertyAnimator)to specify what property to animate and how to animate it. For example, to fade the[View](https://developer.android.com/reference/android/view/View)to transparent, call`alpha(0);`. The[ViewPropertyAnimator](https://developer.android.com/reference/android/view/ViewPropertyAnimator)object handles the details of configuring the underlying[Animator](https://developer.android.com/reference/android/animation/Animator)class and starting it, then rendering the animation.
- Animation background color
  - New[getBackgroundColor()](https://developer.android.com/reference/android/view/animation/Animation#getBackgroundColor())and[setBackgroundColor(int)](https://developer.android.com/reference/android/view/animation/Animation#setBackgroundColor(int))methods let you get/set the background color behind animations, for window animations only. Currently the background must be black, with any desired alpha level.
- Getting animated fraction from`ViewAnimator`
  - A new[getAnimatedFraction()](https://developer.android.com/reference/android/animation/ValueAnimator#getAnimatedFraction())method lets you get the current animation fraction --- the elapsed/interpolated fraction used in the most recent frame update --- from a[ValueAnimator](https://developer.android.com/reference/android/animation/ValueAnimator).

### UI framework

- Forced rendering of a layer
  - A new[buildLayer()](https://developer.android.com/reference/android/view/View#buildLayer())method lets an application force a View's layer to be created and the View rendered into it immediately. For example, an application could use this method to render a View into its layer before starting an animation. If the View is complex, rendering it into the layer before starting the animation will avoid skipping frames.
- Camera distance
  - Applications can use a new method[setCameraDistance(float)](https://developer.android.com/reference/android/view/View#setCameraDistance(float))to set the distance from the camera to a View. This gives applications improved control over 3D transformations of the View, such as rotations.
- Getting a calendar view from a DatePicker
  - A new[getCalendarView()](https://developer.android.com/reference/android/widget/DatePicker#getCalendarView())method lets you get a[CalendarView](https://developer.android.com/reference/android/widget/CalendarView)from a[DatePicker](https://developer.android.com/reference/android/widget/DatePicker)instance.
- Getting callbacks when views are detached
  - A new[View.OnAttachStateChangeListener](https://developer.android.com/reference/android/view/View.OnAttachStateChangeListener)lets you receive callbacks when a View is attached or detached from its window. Use[addOnAttachStateChangeListener()](https://developer.android.com/reference/android/view/View#addOnAttachStateChangeListener(android.view.View.OnAttachStateChangeListener))to add a listener and[addOnAttachStateChangeListener()](https://developer.android.com/reference/android/view/View#removeOnAttachStateChangeListener(android.view.View.OnAttachStateChangeListener))to remove it.
- Fragment breadcrumb listener, new onInflate() signature
  - A new method,[setOnBreadCrumbClickListener()](https://developer.android.com/reference/android/app/FragmentBreadCrumbs#setOnBreadCrumbClickListener(android.app.FragmentBreadCrumbs.OnBreadCrumbClickListener)), provides a hook to let applications intercept fragment-breadcrumb clicks and take any action needed before going to the backstack entry or fragment that was clicked.
  - In the[Fragment](https://developer.android.com/reference/android/app/Fragment)class,[onInflate(attrs, savedInstanceState)](https://developer.android.com/reference/android/app/Fragment#onInflate(android.util.AttributeSet, android.os.Bundle))is deprecated. Please use[onInflate(activity, attrs, savedInstanceState)](https://developer.android.com/reference/android/app/Fragment#onInflate(android.app.Activity, android.util.AttributeSet, android.os.Bundle))instead.
- Display search result in new tab
  - An[EXTRA_NEW_SEARCH](https://developer.android.com/reference/android/app/SearchManager#EXTRA_NEW_SEARCH)data key for[ACTION_WEB_SEARCH](https://developer.android.com/reference/android/content/Intent#ACTION_WEB_SEARCH)intents lets you open a search in a new browser tab, rather than in an existing one.
- Drawable text cursor
  - You can now specify a drawable to use as the text cursor using the new resource attribute[textCursorDrawable](https://developer.android.com/reference/android/R.attr#textCursorDrawable).
- Setting displayed child in remote views
  - A new convenience method,[setDisplayedChild(viewId,
    childIndex)](https://developer.android.com/reference/android/widget/RemoteViews#setDisplayedChild(int, int)), is available in[RemoteViews](https://developer.android.com/reference/android/widget/RemoteViews)subclasses, to let you set the child displayed in[ViewAnimator](https://developer.android.com/reference/android/widget/ViewAnimator)and[AdapterViewAnimator](https://developer.android.com/reference/android/widget/AdapterViewAnimator)subclasses such as[AdapterViewFlipper](https://developer.android.com/reference/android/widget/AdapterViewFlipper),[StackView](https://developer.android.com/reference/android/widget/StackView),[ViewFlipper](https://developer.android.com/reference/android/widget/ViewFlipper), and[ViewSwitcher](https://developer.android.com/reference/android/widget/ViewSwitcher).
- Generic keys for gamepads and other input devices
  - [KeyEvent](https://developer.android.com/reference/android/view/KeyEvent)adds a range of generic keycodes to accommodate gamepad buttons. The class also adds[isGamepadButton(int)](https://developer.android.com/reference/android/view/KeyEvent#isGamepadButton(int))and several other helper methods for working with keycodes.

### Graphics

- Helpers for managing bitmaps
  - [setHasAlpha(boolean)](https://developer.android.com/reference/android/graphics/Bitmap#setHasAlpha(boolean))lets an app indicate that all of the pixels in a Bitmap are known to be opaque (false) or that some of the pixels may contain non-opaque alpha values (true). Note, for some configs (such as RGB_565) this call is ignored, since it does not support per-pixel alpha values. This is meant as a drawing hint, as in some cases a bitmap that is known to be opaque can take a faster drawing case than one that may have non-opaque per-pixel alpha values.
  - [getByteCount()](https://developer.android.com/reference/android/graphics/Bitmap#getByteCount())gets a Bitmap's size in bytes.
  - [getGenerationId()](https://developer.android.com/reference/android/graphics/Bitmap#getGenerationId())lets an application find out whether a Bitmap has been modified, such as for caching.
  - [sameAs(android.graphics.Bitmap)](https://developer.android.com/reference/android/graphics/Bitmap#sameAs(android.graphics.Bitmap))determines whether a given Bitmap differs from the current Bitmap, in dimension, configuration, or pixel data.
- Setting camera location and rotation
  - [Camera](https://developer.android.com/reference/android/graphics/Camera)adds two new methods[rotate()](https://developer.android.com/reference/android/graphics/Camera#rotate(float, float, float))and[setLocation()](https://developer.android.com/reference/android/graphics/Camera#setLocation(float, float, float))for control of the camera's location, for 3D transformations.

### Network

- High-performance Wi-Fi lock
  - A new high-performance Wi-Fi lock lets applications maintain high-performance Wi-Fi connections even when the device screen is off. Applications that stream music, video, or voice for long periods can acquire the high-performance Wi-Fi lock to ensure streaming performance even when the screen is off. Because it uses more power, applications should acquire the high-performance Wi-Fi when there is a need for a long-running active connection.To create a high-performance lock, pass[WIFI_MODE_FULL_HIGH_PERF](https://developer.android.com/reference/android/net/wifi/WifiManager#WIFI_MODE_FULL_HIGH_PERF)as the lock mode in a call to[createWifiLock()](https://developer.android.com/reference/android/net/wifi/WifiManager#createWifiLock(int, java.lang.String)).

- More traffic stats
  - Applications can now access statistics about more types of network usage using new methods in[TrafficStats](https://developer.android.com/reference/android/net/TrafficStats). Applications can use the methods to get UDP stats, packet count, TCP transmit/receive payload bytes and segments for a given UID.
- SIP auth username
  - Applications can now get and set the SIP auth username for a profile using the new methods[getAuthUserName()](https://developer.android.com/reference/android/net/sip/SipProfile#getAuthUserName())and[setAuthUserName()](https://developer.android.com/reference/android/net/sip/SipProfile.Builder#setAuthUserName(java.lang.String)).

### Download Manager

- Handling of completed downloads
  - Applications can now initiate downloads that notify users only on completion. To initiate this type of download, applications pass[VISIBILITY_VISIBLE_NOTIFY_ONLY_COMPLETION](https://developer.android.com/reference/android/app/DownloadManager.Request#VISIBILITY_VISIBLE_NOTIFY_ONLY_COMPLETION)in the[setNotificationVisibility()](https://developer.android.com/reference/android/app/DownloadManager.Request#setNotificationVisibility(int))method of the a request object.
  - A new method,[addCompletedDownload()](https://developer.android.com/reference/android/app/DownloadManager#addCompletedDownload(java.lang.String, java.lang.String, boolean, java.lang.String, java.lang.String, long, boolean)), lets an application add a file to the downloads database, so that it can be managed by the Downloads application.
- Show downloads sorted by size
  - Applications can start the Downloads application in sort-by-size mode by adding the new extra[INTENT_EXTRAS_SORT_BY_SIZE](https://developer.android.com/reference/android/app/DownloadManager#INTENT_EXTRAS_SORT_BY_SIZE)to an[ACTION_VIEW_DOWNLOADS](https://developer.android.com/reference/android/app/DownloadManager#ACTION_VIEW_DOWNLOADS)intent.

### IME framework

- Getting an input method's extra value key
  - The[InputMethodSubtype](https://developer.android.com/reference/android/view/inputmethod/InputMethodSubtype)adds the method[containsExtraValueKey()](https://developer.android.com/reference/android/view/inputmethod/InputMethodSubtype#containsExtraValueKey(java.lang.String))to check whether an ExtraValue string is stored for the subtype and the method[getExtraValueOf()](https://developer.android.com/reference/android/view/inputmethod/InputMethodSubtype#getExtraValueOf(java.lang.String))to extract a specific key value from the ExtraValue hashmap.

### Media

- New streaming audio formats
  - The media framework adds built-in support for raw ADTS AAC content, for improved streaming audio, as well as support for FLAC audio, for highest quality (lossless) compressed audio content. See the[Supported Media Formats](https://developer.android.com/guide/appendix/media-formats)document for more information.

    <br />

### Launch controls on stopped applications

Starting from Android 3.1, the system's package manager keeps track of applications that are in a stopped state and provides a means of controlling their launch from background processes and other applications.

Note that an application's stopped state is not the same as an Activity's stopped state. The system manages those two stopped states separately.

The platform defines two new intent flags that let a sender specify whether the Intent should be allowed to activate components in stopped application.

- [FLAG_INCLUDE_STOPPED_PACKAGES](https://developer.android.com/reference/android/content/Intent#FLAG_INCLUDE_STOPPED_PACKAGES)--- Include intent filters of stopped applications in the list of potential targets to resolve against.
- [FLAG_EXCLUDE_STOPPED_PACKAGES](https://developer.android.com/reference/android/content/Intent#FLAG_EXCLUDE_STOPPED_PACKAGES)--- Exclude intent filters of stopped applications from the list of potential targets.

When neither or both of these flags is defined in an intent, the default behavior is to include filters of stopped applications in the list of potential targets.

Note that the system adds[FLAG_EXCLUDE_STOPPED_PACKAGES](https://developer.android.com/reference/android/content/Intent#FLAG_EXCLUDE_STOPPED_PACKAGES)*to all broadcast intents* . It does this to prevent broadcasts from background services from inadvertently or unnecessarily launching components of stoppped applications. A background service or application can override this behavior by adding the[FLAG_INCLUDE_STOPPED_PACKAGES](https://developer.android.com/reference/android/content/Intent#FLAG_INCLUDE_STOPPED_PACKAGES)flag to broadcast intents that should be allowed to activate stopped applications.

Applications are in a stopped state when they are first installed but are not yet launched and when they are manually stopped by the user (in Manage Applications).

### Notification of application first launch and upgrade

The platform adds improved notification of application first launch and upgrades through two new intent actions:

- [ACTION_PACKAGE_FIRST_LAUNCH](https://developer.android.com/reference/android/content/Intent#ACTION_PACKAGE_FIRST_LAUNCH)--- Sent to the installer package of an application when that application is first launched (that is, the first time it is moved out of a stopped state). The data contains the name of the package.
- [ACTION_MY_PACKAGE_REPLACED](https://developer.android.com/reference/android/content/Intent#ACTION_MY_PACKAGE_REPLACED)--- Notifies an application that it was updated, with a new version was installed over an existing version. This is only sent to the application that was replaced. It does not contain any additional data. To receive it, declare an intent filter for this action. You can use the intent to trigger code that helps get your application back in proper running shape after an upgrade.

  This intent is sent directly to the application, but only if the application was upgraded while it was in started state (not in a stopped state).

### Core utilities

- LRU cache
  - A new[LruCache](https://developer.android.com/reference/android/util/LruCache)class lets your applications benefit from efficient caching. Applications can use the class to reduce the time spent computing or downloading data from the network, while maintaining a sensible memory footprint for the cached data.[LruCache](https://developer.android.com/reference/android/util/LruCache)is a cache that holds strong references to a limited number of values. Each time a value is accessed, it is moved to the head of a queue. When a value is added to a full cache, the value at the end of that queue is evicted and may become eligible for garbage collection.
- File descriptor as`int`
  - You can now get the native file descriptor int for a[ParcelFileDescriptor](https://developer.android.com/reference/android/os/ParcelFileDescriptor)using either of the new methods[getFd()](https://developer.android.com/reference/android/os/ParcelFileDescriptor#getFd())or[detachFd()](https://developer.android.com/reference/android/os/ParcelFileDescriptor#detachFd()).

### WebKit

- File scheme cookies
  - The[CookieManager](https://developer.android.com/reference/android/webkit/CookieManager)now supports cookies that use the`file:`URI scheme. You can use[setAcceptFileSchemeCookies()](https://developer.android.com/reference/android/webkit/CookieManager#setAcceptFileSchemeCookies(boolean))to enable/disable support for file scheme cookies, before constructing an instance of`WebView`or`CookieManager`. In a`CookieManager`instance, you can check whether file scheme cookies is enabled by calling[allowFileSchemeCookies()](https://developer.android.com/reference/android/webkit/CookieManager#allowFileSchemeCookies()).
- Notification of login request
  - To support the browser autologin features introduced in Android 3.0, the new method[onReceivedLoginRequest()](https://developer.android.com/reference/android/webkit/WebViewClient#onReceivedLoginRequest(android.webkit.WebView, java.lang.String, java.lang.String, java.lang.String))notifies the host application that an autologin request for the user was processed.
- Removed classes and interfaces
  - Several classes and interfaces were removed from the public API, after previously being in deprecated state. See the[API Differences Report](https://developer.android.com/sdk/api_diff/12/changes)for more information.

    <br />

### Browser

The Browser application adds the following features to support web applications:

- Support for inline playback of video embedded in HTML5`<video>`tag. Playback is hardware-accelerated where possible.
- Layer support for fixed position elements for all sites (mobile and desktop).

### New feature constants

The platform adds new hardware feature constants that developers can declare in their application manifests, to inform external entities such as Google Play of the application's requirement for new hardware capabilities supported in this version of the platform. Developers declare these and other feature constants in[`<uses-feature>`](https://developer.android.com/guide/topics/manifest/uses-feature-element)manifest elements.

- [android.hardware.usb.accessory](https://developer.android.com/reference/android/content/pm/PackageManager#FEATURE_USB_ACCESSORY)--- The application uses the[USB API](https://developer.android.com/about/versions/android-3.1#usb)to communicate with external hardware devices connected over USB and function as hosts.
- [android.hardware.usb.host](https://developer.android.com/reference/android/content/pm/PackageManager#FEATURE_USB_HOST)--- The application uses the[USB API](https://developer.android.com/about/versions/android-3.1#usb)to communicate with external hardware devices connected over USB and function as devices.

Google Play filters applications based on features declared in[`<uses-feature>`](https://developer.android.com/guide/topics/manifest/uses-feature-element)manifest elements. For more information about declaring features in an application manifest, read[Google Play Filters](https://developer.android.com/google/play/filters).

### API Differences Report

For a detailed view of all API changes in Android 3.1 (API Level 12), see the[API Differences Report](https://developer.android.com/sdk/api_diff/12/changes).

## API Level

The Android 3.1 platform delivers an updated version of the framework API. The Android 3.1 API is assigned an integer identifier ---**12**--- that is stored in the system itself. This identifier, called the "API Level", allows the system to correctly determine whether an application is compatible with the system, prior to installing the application.

To use APIs introduced in Android 3.1 in your application, you need compile the application against the Android library that is provided in the Android 3.1 SDK platform. Depending on your needs, you might also need to add an`android:minSdkVersion="12"`attribute to the`<uses-sdk>`element in the application's manifest.

For more information, read[What is API Level?](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)