API Level: 18

Android 4.3 ([JELLY_BEAN_MR2](https://developer.android.com/reference/android/os/Build.VERSION_CODES#JELLY_BEAN_MR2))
is an update to the Jelly Bean release that offers new features for users and app
developers. This document provides an introduction to the most notable
new APIs.

As an app developer, you should download the Android 4.3 system image
and SDK platform from the [SDK Manager](https://developer.android.com/tools/help/sdk-manager) as
soon as possible. If you don't have a device running Android 4.3 on which to
test your app, use the Android 4.3 system
image to test your app on the [Android emulator](https://developer.android.com/tools/devices/emulator).
Then build your apps against the Android 4.3 platform to begin using the
latest APIs.

### Update your target API level

To better optimize your app for devices running Android 4.3,
you should set your [`targetSdkVersion`](https://developer.android.com/guide/topics/manifest/uses-sdk-element#target) to
`"18"`, install it on an Android 4.3 system image,
test it, then publish an update with this change.

You can use APIs in Android 4.3 while also supporting older versions by adding
conditions to your code that check for the system API level before executing
APIs not supported by your [`minSdkVersion`](https://developer.android.com/guide/topics/manifest/uses-sdk-element#min).
To learn more about maintaining backward compatibility, read [Supporting Different
Platform Versions](https://developer.android.com/training/basics/supporting-devices/platforms).

Various APIs are also available in the Android [Support Library](https://developer.android.com/tools/support-library) that allow you to implement
new features on older versions of the platform.

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

## Important Behavior Changes

If you have previously published an app for Android, be aware that your app might
be affected by changes in Android 4.3.

### If your app uses implicit intents...

Your app might misbehave in a restricted profile environment.

Users in a [restricted profile](https://developer.android.com/about/versions/android-4.3#RestrictedProfiles) environment might not
have all the standard Android apps available. For example, a restricted profile might have the
web browser and camera app disabled. So your app should not make assumptions about which apps are
available, because if you call [startActivity()](https://developer.android.com/reference/android/app/Activity#startActivity(android.content.Intent)) without
verifying whether an app is available to handle the [Intent](https://developer.android.com/reference/android/content/Intent),
your app might crash in a restricted profile.

When using an implicit intent, you should always verify that an app is available to handle the intent by calling [resolveActivity()](https://developer.android.com/reference/android/content/Intent#resolveActivity(android.content.pm.PackageManager)) or [queryIntentActivities()](https://developer.android.com/reference/android/content/pm/PackageManager#queryIntentActivities(android.content.Intent, int)). For example:  

### Kotlin

```kotlin
val intent = Intent(Intent.ACTION_SEND)
...
if (intent.resolveActivity(packageManager) != null) {
    startActivity(intent)
} else {
    Toast.makeText(context, R.string.app_not_available, Toast.LENGTH_LONG).show()
}
```

### Java

```java
Intent intent = new Intent(Intent.ACTION_SEND);
...
if (intent.resolveActivity(getPackageManager()) != null) {
    startActivity(intent);
} else {
    Toast.makeText(context, R.string.app_not_available, Toast.LENGTH_LONG).show();
}
```

### If your app depends on accounts...

Your app might misbehave in a restricted profile environment.

Users within a restricted profile environment do not have access to user accounts by default.
If your app depends on an [Account](https://developer.android.com/reference/android/accounts/Account), then your app might crash or behave
unexpectedly when used in a restricted profile.

If you'd like to prevent restricted profiles from using your app entirely because your
app depends on account information that's sensitive, specify the [`android:requiredAccountType`](https://developer.android.com/guide/topics/manifest/application-element#requiredAccountType) attribute in your manifest's [`<application>`](https://developer.android.com/guide/topics/manifest/application-element)
element.

If you'd like to allow restricted profiles to continue using your app even though they can't
create their own accounts, then you can either disable your app features that require an account
or allow restricted profiles to access the accounts created by the primary user. For more
information, see the section
below about [Supporting accounts in a restricted profile](https://developer.android.com/about/versions/android-4.3#AccountsInProfile).

### If your app uses VideoView...

Your video might appear smaller on Android 4.3.

On previous versions of Android, the [VideoView](https://developer.android.com/reference/android/widget/VideoView) widget incorrectly
calculated the `"wrap_content"` value for [layout_height](https://developer.android.com/reference/android/R.attr#layout_height) and [layout_width](https://developer.android.com/reference/android/R.attr#layout_width) to be the same as `"match_parent"`. So while using `"wrap_content"` for the height or width may have previously provided your desired video layout,
doing so may result in a much smaller video on Android 4.3 and higher. To fix the issue, replace
`"wrap_content"` with `"match_parent"` and verify your video appears as expected on
Android 4.3 as well as on older versions.

## Restricted Profiles

On Android tablets, users can now create restricted profiles based on the primary user.
When users create a restricted profile, they can enable restrictions such as which apps are
available to the profile. A new set of APIs in Android 4.3 also allow you to build fine-grain
restriction settings for the apps you develop. For example, by using the new APIs, you can
allow users to control what type of content is available within your app when running in a
restricted profile environment.

The UI for users to control the restrictions you've built is managed by the system's
Settings application. To make your app's restriction settings appear to the user,
you must declare the restrictions your app provides by creating a [BroadcastReceiver](https://developer.android.com/reference/android/content/BroadcastReceiver) that receives the [ACTION_GET_RESTRICTION_ENTRIES](https://developer.android.com/reference/android/content/Intent#ACTION_GET_RESTRICTION_ENTRIES) intent. The system invokes this intent to query
all apps for available restrictions, then builds the UI to allow the primary user to
manage restrictions for each restricted profile.

In the [onReceive()](https://developer.android.com/reference/android/content/BroadcastReceiver#onReceive(android.content.Context, android.content.Intent)) method of
your [BroadcastReceiver](https://developer.android.com/reference/android/content/BroadcastReceiver), you must create a [RestrictionEntry](https://developer.android.com/reference/android/content/RestrictionEntry) for each restriction your app provides. Each [RestrictionEntry](https://developer.android.com/reference/android/content/RestrictionEntry) defines a restriction title, description, and one of the
following data types:

- [TYPE_BOOLEAN](https://developer.android.com/reference/android/content/RestrictionEntry#TYPE_BOOLEAN) for a restriction that is either true or false.
- [TYPE_CHOICE](https://developer.android.com/reference/android/content/RestrictionEntry#TYPE_CHOICE) for a restriction that has multiple choices that are mutually exclusive (radio button choices).
- [TYPE_MULTI_SELECT](https://developer.android.com/reference/android/content/RestrictionEntry#TYPE_MULTI_SELECT) for a restriction that has multiple choices that are *not* mutually exclusive (checkbox choices).

You then put all the [RestrictionEntry](https://developer.android.com/reference/android/content/RestrictionEntry) objects into an [ArrayList](https://developer.android.com/reference/java/util/ArrayList) and put it into the broadcast receiver's result as the value for the
[EXTRA_RESTRICTIONS_LIST](https://developer.android.com/reference/android/content/Intent#EXTRA_RESTRICTIONS_LIST) extra.

The system creates the UI for your app's restrictions in the Settings app and saves each
restriction with the unique key you provided for each [RestrictionEntry](https://developer.android.com/reference/android/content/RestrictionEntry)
object. When the user opens your app, you can query for any current restrictions by
calling [getApplicationRestrictions()](https://developer.android.com/reference/android/os/UserManager#getApplicationRestrictions(java.lang.String)).
This returns a [Bundle](https://developer.android.com/reference/android/os/Bundle) containing the key-value pairs for each restriction
you defined with the [RestrictionEntry](https://developer.android.com/reference/android/content/RestrictionEntry) objects.

If you want to provide more specific restrictions that can't be handled by boolean, single
choice, and multi-choice values, then you can create an activity where the user can specify the
restrictions and allow users to open that activity from the restriction settings. In your
broadcast receiver, include the [EXTRA_RESTRICTIONS_INTENT](https://developer.android.com/reference/android/content/Intent#EXTRA_RESTRICTIONS_INTENT) extra
in the result [Bundle](https://developer.android.com/reference/android/os/Bundle). This extra must specify an [Intent](https://developer.android.com/reference/android/content/Intent)
indicating the [Activity](https://developer.android.com/reference/android/app/Activity) class to launch (use the
[putParcelable()](https://developer.android.com/reference/android/os/Bundle#putParcelable(java.lang.String, android.os.Parcelable)) method to pass [EXTRA_RESTRICTIONS_INTENT](https://developer.android.com/reference/android/content/Intent#EXTRA_RESTRICTIONS_INTENT) with the intent).
When the primary user enters your activity to set custom restrictions, your
activity must then return a result containing the restriction values in an extra using either
the [EXTRA_RESTRICTIONS_LIST](https://developer.android.com/reference/android/content/Intent#EXTRA_RESTRICTIONS_LIST) or [EXTRA_RESTRICTIONS_BUNDLE](https://developer.android.com/reference/android/content/Intent#EXTRA_RESTRICTIONS_BUNDLE) key, depending on whether you specify
[RestrictionEntry](https://developer.android.com/reference/android/content/RestrictionEntry) objects or key-value pairs, respectively.

### Supporting accounts in a restricted profile

Any accounts added to the primary user are available to a restricted profile, but the
accounts are not accessible from the [AccountManager](https://developer.android.com/reference/android/accounts/AccountManager) APIs by default.
If you attempt to add an account with [AccountManager](https://developer.android.com/reference/android/accounts/AccountManager) while in a restricted
profile, you will get a failure result. Due to these restrictions, you have the following
three options:
- **Allow access to the owner's accounts from a restricted profile.**

  To get access to an account from a restricted profile, you must add the [`android:restrictedAccountType`](https://developer.android.com/guide/topics/manifest/application-element#restrictedAccountType) attribute to the [\<application\>](https://developer.android.com/guide/topics/manifest/application-element) tag:  

  ```carbon
  <application ...
      android:restrictedAccountType="com.example.account.type" >
  ```

  **Caution:** Enabling this attribute provides your
  app access to the primary user's accounts from restricted profiles. So you should allow this
  only if the information displayed by your app does not reveal personally identifiable
  information (PII) that's considered sensitive. The system settings will inform the primary
  user that your app grants restricted profiles to their accounts, so it should be clear to the user
  that account access is important for your app's functionality. If possible, you should also
  provide adequate restriction controls for the primary user that define how much account access
  is allowed in your app.
- **Disable certain functionality when unable to modify accounts.**

  If you want to use accounts, but don't actually require them for your app's primary
  functionality, you can check for account availability and disable features when not available.
  You should first check if there is an existing account available. If not, then query whether
  it's possible to create a new account by calling [getUserRestrictions()](https://developer.android.com/reference/android/os/UserManager#getUserRestrictions()) and check the [DISALLOW_MODIFY_ACCOUNTS](https://developer.android.com/reference/android/os/UserManager#DISALLOW_MODIFY_ACCOUNTS) extra in the result. If it is `true`,
  then you should disable whatever functionality of your app requires access to accounts.
  For example:  

  ### Kotlin

  ```kotlin
  val um = context.getSystemService(Context.USER_SERVICE) as UserManager
  val restrictions: Bundle = um.userRestrictions
  if (restrictions.getBoolean(UserManager.DISALLOW_MODIFY_ACCOUNTS, false)) {
      // cannot add accounts, disable some functionality
  }
  ```

  ### Java

  ```java
  UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
  Bundle restrictions = um.getUserRestrictions();
  if (restrictions.getBoolean(UserManager.DISALLOW_MODIFY_ACCOUNTS, false)) {
      // cannot add accounts, disable some functionality
  }
  ```

  **Note:** In this scenario, you should *not* declare
  any new attributes in your manifest file.
- **Disable your app when unable to access private accounts.**

  If it's instead important that your app not be available to restricted profiles because
  your app depends on sensitive personal information in an account (and because restricted profiles
  currently cannot add new accounts), add
  the [`android:requiredAccountType`](https://developer.android.com/guide/topics/manifest/application-element#requiredAccountType) attribute to the [\<application\>](https://developer.android.com/guide/topics/manifest/application-element) tag:  

  ```carbon
  <application ...
      android:requiredAccountType="com.example.account.type" >
  ```

  For example, the Gmail app uses this attribute to disable itself for restricted profiles,
  because the owner's personal email should not be available to restricted profiles.

## Wireless and Connectivity

### Bluetooth Low Energy (Smart Ready)

- Android now supports Bluetooth Low Energy (LE) with new APIs in [android.bluetooth](https://developer.android.com/reference/android/bluetooth/package-summary). With the new APIs, you can build Android apps that communicate with Bluetooth Low Energy peripherals such as heart rate monitors and pedometers.
- Because Bluetooth LE is a hardware feature that is not available on all Android-powered devices, you must declare in your manifest file a [`<uses-feature>`](https://developer.android.com/guide/topics/manifest/uses-feature-element) element for `"android.hardware.bluetooth_le"`:  

```scdoc
<uses-feature android:name="android.hardware.bluetooth_le" android:required="true" />
```
- If you're already familiar with Android's Classic Bluetooth APIs, notice that using the Bluetooth LE APIs has some differences. Most importantly is that there's now a [BluetoothManager](https://developer.android.com/reference/android/bluetooth/BluetoothManager) class that you should use for some high level operations such as acquiring a [BluetoothAdapter](https://developer.android.com/reference/android/bluetooth/BluetoothAdapter), getting a list of connected devices, and checking the state of a device. For example, here's how you should now get the [BluetoothAdapter](https://developer.android.com/reference/android/bluetooth/BluetoothAdapter):  

### Kotlin

```kotlin
val bluetoothManager = getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager
bluetoothAdapter = bluetoothManager.adapter
```

### Java

```java
final BluetoothManager bluetoothManager =
        (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
bluetoothAdapter = bluetoothManager.getAdapter();
```
- To discover Bluetooth LE peripherals, call [startLeScan()](https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#startLeScan(android.bluetooth.BluetoothAdapter.LeScanCallback)) on the [BluetoothAdapter](https://developer.android.com/reference/android/bluetooth/BluetoothAdapter), passing it an implementation of the [BluetoothAdapter.LeScanCallback](https://developer.android.com/reference/android/bluetooth/BluetoothAdapter.LeScanCallback) interface. When the Bluetooth adapter detects a Bluetooth LE peripheral, your [BluetoothAdapter.LeScanCallback](https://developer.android.com/reference/android/bluetooth/BluetoothAdapter.LeScanCallback) implementation receives a call to the [onLeScan()](https://developer.android.com/reference/android/bluetooth/BluetoothAdapter.LeScanCallback#onLeScan(android.bluetooth.BluetoothDevice, int, byte[])) method. This method provides you with a [BluetoothDevice](https://developer.android.com/reference/android/bluetooth/BluetoothDevice) object representing the detected device, the RSSI value for the device, and a byte array containing the device's advertisement record.
- If you want to scan for only specific types of peripherals, you can instead call [startLeScan()](https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#startLeScan(android.bluetooth.BluetoothAdapter.LeScanCallback)) and include an array of [UUID](https://developer.android.com/reference/java/util/UUID) objects that specify the GATT services your app supports.
- **Note:** You can only scan for Bluetooth LE devices *or* scan for Classic Bluetooth devices using previous APIs. You cannot scan for both LE and Classic Bluetooth devices at once.
- To then connect to a Bluetooth LE peripheral, call [connectGatt()](https://developer.android.com/reference/android/bluetooth/BluetoothDevice#connectGatt(android.content.Context, boolean, android.bluetooth.BluetoothGattCallback)) on the corresponding [BluetoothDevice](https://developer.android.com/reference/android/bluetooth/BluetoothDevice) object, passing it an implementation of [BluetoothGattCallback](https://developer.android.com/reference/android/bluetooth/BluetoothGattCallback). Your implementation of [BluetoothGattCallback](https://developer.android.com/reference/android/bluetooth/BluetoothGattCallback) receives callbacks regarding the connectivity state with the device and other events. It's during the [onConnectionStateChange()](https://developer.android.com/reference/android/bluetooth/BluetoothGattCallback#onConnectionStateChange(android.bluetooth.BluetoothGatt, int, int)) callback that you can begin communicating with the device if the method passes [STATE_CONNECTED](https://developer.android.com/reference/android/bluetooth/BluetoothProfile#STATE_CONNECTED) as the new state.
- Accessing Bluetooth features on a device also requires that your app request certain Bluetooth user permissions. For more information, see the [Bluetooth Low Energy](https://developer.android.com/guide/topics/connectivity/bluetooth-le) API guide.

### Wi-Fi scan-only mode

- When attempting to identify the user's location, Android may use Wi-Fi to help determine the location by scanning nearby access points. However, users often keep Wi-Fi turned off to conserve battery, resulting in location data that's less accurate. Android now includes a scan-only mode that allows the device Wi-Fi to scan access points to help obtain the location without connecting to an access point, thus greatly reducing battery usage.
- If you want to acquire the user's location but Wi-Fi is currently off, you can request the user to enable Wi-Fi scan-only mode by calling [startActivity()](https://developer.android.com/reference/android/content/Context#startActivity(android.content.Intent)) with the action [ACTION_REQUEST_SCAN_ALWAYS_AVAILABLE](https://developer.android.com/reference/android/net/wifi/WifiManager#ACTION_REQUEST_SCAN_ALWAYS_AVAILABLE).

### Wi-Fi configuration

- New [WifiEnterpriseConfig](https://developer.android.com/reference/android/net/wifi/WifiEnterpriseConfig) APIs allow enterprise-oriented services to automate Wi-Fi configuration for managed devices.

### Quick response for incoming calls

- Since Android 4.0, a feature called "Quick response" allows users to respond to incoming calls with an immediate text message without needing to pick up the call or unlock the device. Until now, these quick messages were always handled by the default Messaging app. Now any app can declare its capability to handle these messages by creating a [Service](https://developer.android.com/reference/android/app/Service) with an intent filter for [ACTION_RESPOND_VIA_MESSAGE](https://developer.android.com/reference/android/telephony/TelephonyManager#ACTION_RESPOND_VIA_MESSAGE).
- When the user responds to an incoming call with a quick response, the Phone app sends the [ACTION_RESPOND_VIA_MESSAGE](https://developer.android.com/reference/android/telephony/TelephonyManager#ACTION_RESPOND_VIA_MESSAGE) intent with a URI describing the recipient (the caller) and the [EXTRA_TEXT](https://developer.android.com/reference/android/content/Intent#EXTRA_TEXT) extra with the message the user wants to send. When your service receives the intent, it should deliver the message and immediately stop itself (your app should not show an activity).
- In order to receive this intent, you must declare the [SEND_RESPOND_VIA_MESSAGE](https://developer.android.com/reference/android/Manifest.permission#SEND_RESPOND_VIA_MESSAGE) permission.

## Multimedia

### MediaExtractor and MediaCodec enhancements

- Android now makes it easier for you to write your own Dynamic Adaptive Streaming over HTTP (DASH) players in accordance with the ISO/IEC 23009-1 standard, using existing APIs in [MediaCodec](https://developer.android.com/reference/android/media/MediaCodec) and [MediaExtractor](https://developer.android.com/reference/android/media/MediaExtractor). The framework underlying these APIs has been updated to support parsing of fragmented MP4 files, but your app is still responsible for parsing the MPD metadata and passing the individual streams to [MediaExtractor](https://developer.android.com/reference/android/media/MediaExtractor).
- If you want to use DASH with encrypted content, notice that the [getSampleCryptoInfo()](https://developer.android.com/reference/android/media/MediaExtractor#getSampleCryptoInfo(android.media.MediaCodec.CryptoInfo)) method returns the [MediaCodec.CryptoInfo](https://developer.android.com/reference/android/media/MediaCodec.CryptoInfo) metadata describing the structure of each encrypted media sample. Also, the [getPsshInfo()](https://developer.android.com/reference/android/media/MediaExtractor#getPsshInfo()) method has been added to [MediaExtractor](https://developer.android.com/reference/android/media/MediaExtractor) so you can access the PSSH metadata for your DASH media. This method returns a map of [UUID](https://developer.android.com/reference/java/util/UUID) objects to bytes, with the [UUID](https://developer.android.com/reference/java/util/UUID) specifying the crypto scheme, and the bytes being the data specific to that scheme.

### Media DRM

- The new [MediaDrm](https://developer.android.com/reference/android/media/MediaDrm) class provides a modular solution for digital rights management (DRM) with your media content by separating DRM concerns from media playback. For instance, this API separation allows you to play back Widevine-encrypted content without having to use the Widevine media format. This DRM solution also supports DASH Common Encryption so you can use a variety of DRM schemes with your streaming content.
- You can use [MediaDrm](https://developer.android.com/reference/android/media/MediaDrm) to obtain opaque key-request messages and process key-response messages from the server for license acquisition and provisioning. Your app is responsible for handling the network communication with the servers; the [MediaDrm](https://developer.android.com/reference/android/media/MediaDrm) class provides only the ability to generate and process the messages.
- The [MediaDrm](https://developer.android.com/reference/android/media/MediaDrm) APIs are intended to be used in conjunction with the [MediaCodec](https://developer.android.com/reference/android/media/MediaCodec) APIs that were introduced in Android 4.1 (API level 16), including [MediaCodec](https://developer.android.com/reference/android/media/MediaCodec) for encoding and decoding your content, [MediaCrypto](https://developer.android.com/reference/android/media/MediaCrypto) for handling encrypted content, and [MediaExtractor](https://developer.android.com/reference/android/media/MediaExtractor) for extracting and demuxing your content.
- You must first construct [MediaExtractor](https://developer.android.com/reference/android/media/MediaExtractor) and [MediaCodec](https://developer.android.com/reference/android/media/MediaCodec) objects. You can then access the DRM-scheme-identifying [UUID](https://developer.android.com/reference/java/util/UUID), typically from metadata in the content, and use it to construct an instance of a [MediaDrm](https://developer.android.com/reference/android/media/MediaDrm) object with its constructor.

### Video encoding from a Surface

- Android 4.1 (API level 16) added the [MediaCodec](https://developer.android.com/reference/android/media/MediaCodec) class for low-level encoding and decoding of media content. When encoding video, Android 4.1 required that you provide the media with a [ByteBuffer](https://developer.android.com/reference/java/nio/ByteBuffer) array, but Android 4.3 now allows you to use a [Surface](https://developer.android.com/reference/android/view/Surface) as the input to an encoder. For instance, this allows you to encode input from an existing video file or using frames generated from OpenGL ES.
- To use a [Surface](https://developer.android.com/reference/android/view/Surface) as the input to your encoder, first call [configure()](https://developer.android.com/reference/android/media/MediaCodec#configure(android.media.MediaFormat, android.view.Surface, android.media.MediaCrypto, int)) for your [MediaCodec](https://developer.android.com/reference/android/media/MediaCodec). Then call [createInputSurface()](https://developer.android.com/reference/android/media/MediaCodec#createInputSurface()) to receive the [Surface](https://developer.android.com/reference/android/view/Surface) upon which you can stream your media.
- For example, you can use the given [Surface](https://developer.android.com/reference/android/view/Surface) as the window for an OpenGL context by passing it to [eglCreateWindowSurface()](https://developer.android.com/reference/android/opengl/EGL14#eglCreateWindowSurface(android.opengl.EGLDisplay, android.opengl.EGLConfig, java.lang.Object, int[], int)). Then while rendering the surface, call [eglSwapBuffers()](https://developer.android.com/reference/android/opengl/EGL14#eglSwapBuffers(android.opengl.EGLDisplay, android.opengl.EGLSurface)) to pass the frame to the [MediaCodec](https://developer.android.com/reference/android/media/MediaCodec).
- To begin encoding, call [start()](https://developer.android.com/reference/android/media/MediaCodec#start()) on the [MediaCodec](https://developer.android.com/reference/android/media/MediaCodec). When done, call [signalEndOfInputStream()](https://developer.android.com/reference/android/media/MediaCodec#signalEndOfInputStream()) to terminate encoding, and call [release()](https://developer.android.com/reference/android/view/Surface#release()) on the [Surface](https://developer.android.com/reference/android/view/Surface).

### Media muxing

- The new [MediaMuxer](https://developer.android.com/reference/android/media/MediaMuxer) class enables multiplexing between one audio stream and one video stream. These APIs serve as a counterpart to the [MediaExtractor](https://developer.android.com/reference/android/media/MediaExtractor) class added in Android 4.2 for de-multiplexing (demuxing) media.
- Supported output formats are defined in [MediaMuxer.OutputFormat](https://developer.android.com/reference/android/media/MediaMuxer.OutputFormat). Currently, MP4 is the only supported output format and [MediaMuxer](https://developer.android.com/reference/android/media/MediaMuxer) currently supports only one audio stream and/or one video stream at a time.
- [MediaMuxer](https://developer.android.com/reference/android/media/MediaMuxer) is mostly designed to work with [MediaCodec](https://developer.android.com/reference/android/media/MediaCodec) so you can perform video processing through [MediaCodec](https://developer.android.com/reference/android/media/MediaCodec) then save the output to an MP4 file through [MediaMuxer](https://developer.android.com/reference/android/media/MediaMuxer). You can also use [MediaMuxer](https://developer.android.com/reference/android/media/MediaMuxer) in combination with [MediaExtractor](https://developer.android.com/reference/android/media/MediaExtractor) to perform media editing without the need to encode or decode.

### Playback progress and scrubbing for RemoteControlClient

- In Android 4.0 (API level 14), the [RemoteControlClient](https://developer.android.com/reference/android/media/RemoteControlClient) was added to enable media playback controls from remote control clients such as the controls available on the lock screen. Android 4.3 now provides the ability for such controllers to display the playback position and controls for scrubbing the playback. If you've enabled remote control for your media app with the [RemoteControlClient](https://developer.android.com/reference/android/media/RemoteControlClient) APIs, then you can allow playback scrubbing by implementing two new interfaces.
- First, you must enable the [FLAG_KEY_MEDIA_POSITION_UPDATE](https://developer.android.com/reference/android/media/RemoteControlClient#FLAG_KEY_MEDIA_POSITION_UPDATE) flag by passing it to [setTransportControlsFlags()](https://developer.android.com/reference/android/media/RemoteControlClient#setTransportControlFlags(int)).
- Then implement the following two new interfaces:

[RemoteControlClient.OnGetPlaybackPositionListener](https://developer.android.com/reference/android/media/RemoteControlClient.OnGetPlaybackPositionListener)
:   This includes the callback [onGetPlaybackPosition()](https://developer.android.com/reference/android/media/RemoteControlClient.OnGetPlaybackPositionListener#onGetPlaybackPosition()), which requests the current position
    of your media when the remote control needs to update the progress in its UI.

[RemoteControlClient.OnPlaybackPositionUpdateListener](https://developer.android.com/reference/android/media/RemoteControlClient.OnPlaybackPositionUpdateListener)
:   This includes the callback [onPlaybackPositionUpdate()](https://developer.android.com/reference/android/media/RemoteControlClient.OnPlaybackPositionUpdateListener#onPlaybackPositionUpdate(long)), which
    tells your app the new time code for your media when the user scrubs the playback with the
    remote control UI.

    Once you update your playback with the new position, call [setPlaybackState()](https://developer.android.com/reference/android/media/RemoteControlClient#setPlaybackState(int)) to indicate the
    new playback state, position, and speed.

- With these interfaces defined, you can set them for your [RemoteControlClient](https://developer.android.com/reference/android/media/RemoteControlClient) by calling [setOnGetPlaybackPositionListener()](https://developer.android.com/reference/android/media/RemoteControlClient#setOnGetPlaybackPositionListener(android.media.RemoteControlClient.OnGetPlaybackPositionListener)) and [setPlaybackPositionUpdateListener()](https://developer.android.com/reference/android/media/RemoteControlClient#setPlaybackPositionUpdateListener(android.media.RemoteControlClient.OnPlaybackPositionUpdateListener)), respectively.

## Graphics

### Support for OpenGL ES 3.0

- Android 4.3 adds Java interfaces and native support for OpenGL ES 3.0. Key new functionality provided in OpenGL ES 3.0 includes:
  - Acceleration of advanced visual effects
  - High quality ETC2/EAC texture compression as a standard feature
  - A new version of the GLSL ES shading language with integer and 32-bit floating point support
  - Advanced texture rendering
  - Broader standardization of texture size and render-buffer formats
- The Java interface for OpenGL ES 3.0 on Android is provided with [GLES30](https://developer.android.com/reference/android/opengl/GLES30). When using OpenGL ES 3.0, be sure that you declare it in your manifest file with the [\<uses-feature\>](https://developer.android.com/guide/topics/manifest/uses-feature-element) tag and the `android:glEsVersion` attribute. For example:  

```text
<manifest>
    <uses-feature android:glEsVersion="0x00030000" />
    ...
</manifest>
```
- And remember to specify the OpenGL ES context by calling [setEGLContextClientVersion()](https://developer.android.com/reference/android/opengl/GLSurfaceView#setEGLContextClientVersion(int)), passing `3` as the version.
- For more information about using OpenGL ES, including how to check the device's supported OpenGL ES version at runtime, see the [OpenGL ES](https://developer.android.com/develop/ui/views/graphics/opengl/about-opengl) API guide.

### Mipmapping for drawables

- Using a mipmap as the source for your bitmap or drawable is a simple way to provide a quality image and various image scales, which can be particularly useful if you expect your image to be scaled during an animation.
- Android 4.2 (API level 17) added support for mipmaps in the [Bitmap](https://developer.android.com/reference/android/graphics/Bitmap) class---Android swaps the mip images in your [Bitmap](https://developer.android.com/reference/android/graphics/Bitmap) when you've supplied a mipmap source and have enabled [setHasMipMap()](https://developer.android.com/reference/android/graphics/Bitmap#setHasMipMap(boolean)). Now in Android 4.3, you can enable mipmaps for a [BitmapDrawable](https://developer.android.com/reference/android/graphics/drawable/BitmapDrawable) object as well, by providing a mipmap asset and setting the `android:mipMap` attribute in a bitmap resource file or by calling [hasMipMap()](https://developer.android.com/reference/android/graphics/drawable/BitmapDrawable#hasMipMap()).

## User Interface

### View overlays

- The new [ViewOverlay](https://developer.android.com/reference/android/view/ViewOverlay) class provides a transparent layer on top of a [View](https://developer.android.com/reference/android/view/View) on which you can add visual content and which does not affect the layout hierarchy. You can get a [ViewOverlay](https://developer.android.com/reference/android/view/ViewOverlay) for any [View](https://developer.android.com/reference/android/view/View) by calling [getOverlay()](https://developer.android.com/reference/android/view/View#getOverlay()). The overlay always has the same size and position as its host view (the view from which it was created), allowing you to add content that appears in front of the host view, but which cannot extend the bounds of that host view.
- Using a [ViewOverlay](https://developer.android.com/reference/android/view/ViewOverlay) is particularly useful when you want to create animations such as sliding a view outside of its container or moving items around the screen without affecting the view hierarchy. However, because the usable area of an overlay is restricted to the same area as its host view, if you want to animate a view moving outside its position in the layout, you must use an overlay from a parent view that has the desired layout bounds.
- When you create an overlay for a widget view such as a [Button](https://developer.android.com/reference/android/widget/Button), you can add [Drawable](https://developer.android.com/reference/android/graphics/drawable/Drawable) objects to the overlay by calling [add(Drawable)](https://developer.android.com/reference/android/view/ViewOverlay#add(android.graphics.drawable.Drawable)). If you call [getOverlay()](https://developer.android.com/reference/android/view/ViewGroup#getOverlay()) for a layout view, such as [RelativeLayout](https://developer.android.com/reference/android/widget/RelativeLayout), the object returned is a [ViewGroupOverlay](https://developer.android.com/reference/android/view/ViewGroupOverlay). The [ViewGroupOverlay](https://developer.android.com/reference/android/view/ViewGroupOverlay) class is a subclass of [ViewOverlay](https://developer.android.com/reference/android/view/ViewOverlay) that also allows you to add [View](https://developer.android.com/reference/android/view/View) objects by calling [add(View)](https://developer.android.com/reference/android/view/ViewGroupOverlay#add(android.view.View)).
- **Note:** All drawables and views that you add to an overlay are visual only. They cannot receive focus or input events.
- For example, the following code animates a view sliding to the right by placing the view in the parent view's overlay, then performing a translation animation on that view:  

### Kotlin

```kotlin
val view: View? = findViewById(R.id.view_to_remove)
val container: ViewGroup? = view?.parent as ViewGroup

container?.apply {
    overlay.add(view)
    ObjectAnimator.ofFloat(view, "translationX", right.toFloat())
            .start()
}
```

### Java

```java
View view = findViewById(R.id.view_to_remove);
ViewGroup container = (ViewGroup) view.getParent();
container.getOverlay().add(view);
ObjectAnimator anim = ObjectAnimator.ofFloat(view, "translationX", container.getRight());
anim.start();
```

### Optical bounds layout

- For views that contain nine-patch background images, you can now specify that they should be aligned with neighboring views based on the "optical" bounds of the background image rather than the "clip" bounds of the view.
- For example, figures 1 and 2 each show the same layout, but the version in figure 1 is using clip bounds (the default behavior), while figure 2 is using optical bounds. Because the nine-patch images used for the button and the photo frame include padding around the edges, they don't appear to align with each other or the text when using clip bounds.
- **Note:** The screenshot in figures 1 and 2 have the "Show layout bounds" developer setting enabled. For each view, red lines indicate the optical bounds, blue lines indicate the clip bounds, and pink indicates margins.  
![](https://developer.android.com/static/images/tools/clipbounds_2x.png)

**Figure 1.** Layout using clip bounds (default).  
![](https://developer.android.com/static/images/tools/opticalbounds_2x.png)

**Figure 2.** Layout using optical bounds.
- To align the views based on their optical bounds, set the `android:layoutMode` attribute to `"opticalBounds"` in one of the parent layouts. For example:  

```text
<LinearLayout android:layoutMode="opticalBounds" ... >
```  
![](https://developer.android.com/static/images/tools/ninepatch_opticalbounds_2x.png)

**Figure 3.** Zoomed view of the Holo button nine-patch with
optical bounds.
- For this to work, the nine-patch images applied to the background of your views must specify the optical bounds using red lines along the bottom and right-side of the nine-patch file (as shown in figure 3). The red lines indicate the region that should be subtracted from the clip bounds, leaving the optical bounds of the image.
- When you enable optical bounds for a [ViewGroup](https://developer.android.com/reference/android/view/ViewGroup) in your layout, all descendant views inherit the optical bounds layout mode unless you override it for a group by setting `android:layoutMode` to `"clipBounds"`. All layout elements also honor the optical bounds of their child views, adapting their own bounds based on the optical bounds of the views within them. However, layout elements (subclasses of [ViewGroup](https://developer.android.com/reference/android/view/ViewGroup)) currently do not support optical bounds for nine-patch images applied to their own background.
- If you create a custom view by subclassing [View](https://developer.android.com/reference/android/view/View), [ViewGroup](https://developer.android.com/reference/android/view/ViewGroup), or any subclasses thereof, your view will inherit these optical bound behaviors.
- **Note:** All widgets supported by the Holo theme have been updated with optical bounds, including [Button](https://developer.android.com/reference/android/widget/Button), [Spinner](https://developer.android.com/reference/android/widget/Spinner), [EditText](https://developer.android.com/reference/android/widget/EditText), and others. So you can immediately benefit by setting the `android:layoutMode` attribute to `"opticalBounds"` if your app applies a Holo theme ([Theme.Holo](https://developer.android.com/reference/android/R.style#Theme_Holo), [Theme.Holo.Light](https://developer.android.com/reference/android/R.style#Theme_Holo_Light), etc.).
- To specify optical bounds for your own nine-patch images with the [Draw 9-patch](https://developer.android.com/tools/help/draw9patch) tool, hold Control when clicking on the border pixels.

### Animation for Rect values

- You can now animate between two [Rect](https://developer.android.com/reference/android/graphics/Rect) values with the new [RectEvaluator](https://developer.android.com/reference/android/animation/RectEvaluator). This new class is an implementation of [TypeEvaluator](https://developer.android.com/reference/android/animation/TypeEvaluator) that you can pass to [ValueAnimator.setEvaluator()](https://developer.android.com/reference/android/animation/ValueAnimator#setEvaluator(android.animation.TypeEvaluator)).

### Window attach and focus listener

- Previously, if you wanted to listen for when your view attached/detached to the window or when its focus changed, you needed to override the [View](https://developer.android.com/reference/android/view/View) class to implement [onAttachedToWindow()](https://developer.android.com/reference/android/view/View#onAttachedToWindow()) and [onDetachedFromWindow()](https://developer.android.com/reference/android/view/View#onDetachedFromWindow()), or [onWindowFocusChanged()](https://developer.android.com/reference/android/view/View#onWindowFocusChanged(boolean)), respectively.
- Now, to receive attach and detach events you can instead implement [ViewTreeObserver.OnWindowAttachListener](https://developer.android.com/reference/android/view/ViewTreeObserver.OnWindowAttachListener) and set it on a view with [addOnWindowAttachListener()](https://developer.android.com/reference/android/view/ViewTreeObserver#addOnWindowAttachListener(android.view.ViewTreeObserver.OnWindowAttachListener)). And to receive focus events, you can implement [ViewTreeObserver.OnWindowFocusChangeListener](https://developer.android.com/reference/android/view/ViewTreeObserver.OnWindowFocusChangeListener) and set it on a view with [addOnWindowFocusChangeListener()](https://developer.android.com/reference/android/view/ViewTreeObserver#addOnWindowFocusChangeListener(android.view.ViewTreeObserver.OnWindowFocusChangeListener)).

### TV overscan support

- To be sure your app fills the entire screen on every television, you can now enable overscan for you app layout. Overscan mode is determined by the [FLAG_LAYOUT_IN_OVERSCAN](https://developer.android.com/reference/android/view/WindowManager.LayoutParams#FLAG_LAYOUT_IN_OVERSCAN) flag, which you can enable with platform themes such as [Theme_DeviceDefault_NoActionBar_Overscan](https://developer.android.com/reference/android/R.style#Theme_DeviceDefault_NoActionBar_Overscan) or by enabling the [windowOverscan](https://developer.android.com/reference/android/R.attr#windowOverscan) style in a custom theme.

### Screen orientation

- The [`<activity>`](https://developer.android.com/guide/topics/manifest/activity-element) tag's [`screenOrientation`](https://developer.android.com/guide/topics/manifest/activity-element#screen) attribute now supports additional values to honor the user's preference for auto-rotation:

`"userLandscape"`
:   Behaves the same as `"sensorLandscape"`, except if the user disables auto-rotate
    then it locks in the normal landscape orientation and will not flip.

`"userPortrait"`
:   Behaves the same as `"sensorPortrait"`, except if the user disables auto-rotate then
    it locks in the normal portrait orientation and will not flip.

`"fullUser"`
:   Behaves the same as `"fullSensor"` and allows rotation in all four directions, except
    if the user disables auto-rotate then it locks in the user's preferred orientation.
- Additionally, you can now also declare `"locked"` to lock your app's orientation into the screen's current orientation.

### Rotation animations

- The new [rotationAnimation](https://developer.android.com/reference/android/view/WindowManager.LayoutParams#rotationAnimation) field in [WindowManager](https://developer.android.com/reference/android/view/WindowManager) allows you to select between one of three animations you want to use when the system switches screen orientations. The three animations are:
  - [ROTATION_ANIMATION_CROSSFADE](https://developer.android.com/reference/android/view/WindowManager.LayoutParams#ROTATION_ANIMATION_CROSSFADE)
  - [ROTATION_ANIMATION_JUMPCUT](https://developer.android.com/reference/android/view/WindowManager.LayoutParams#ROTATION_ANIMATION_JUMPCUT)
  - [ROTATION_ANIMATION_ROTATE](https://developer.android.com/reference/android/view/WindowManager.LayoutParams#ROTATION_ANIMATION_ROTATE)
- **Note:** These animations are available only if you've set your activity to use "fullscreen" mode, which you can enable with themes such as [Theme.Holo.NoActionBar.Fullscreen](https://developer.android.com/reference/android/R.style#Theme_Holo_NoActionBar_Fullscreen).
- For example, here's how you can enable the "crossfade" animation:  

### Kotlin

```kotlin
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    val params: WindowManager.LayoutParams = window.attributes
    params.rotationAnimation = WindowManager.LayoutParams.ROTATION_ANIMATION_CROSSFADE
    window.attributes = params
    ...
}
```

### Java

```java
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    WindowManager.LayoutParams params = getWindow().getAttributes();
    params.rotationAnimation = WindowManager.LayoutParams.ROTATION_ANIMATION_CROSSFADE;
    getWindow().setAttributes(params);
    ...
}
```

## User Input

### New sensor types

- The new [TYPE_GAME_ROTATION_VECTOR](https://developer.android.com/reference/android/hardware/Sensor#TYPE_GAME_ROTATION_VECTOR) sensor allows you to detect the device's rotations without worrying about magnetic interferences. Unlike the [TYPE_ROTATION_VECTOR](https://developer.android.com/reference/android/hardware/Sensor#TYPE_ROTATION_VECTOR) sensor, the [TYPE_GAME_ROTATION_VECTOR](https://developer.android.com/reference/android/hardware/Sensor#TYPE_GAME_ROTATION_VECTOR) is not based on magnetic north.
- The new [TYPE_GYROSCOPE_UNCALIBRATED](https://developer.android.com/reference/android/hardware/Sensor#TYPE_GYROSCOPE_UNCALIBRATED) and [TYPE_MAGNETIC_FIELD_UNCALIBRATED](https://developer.android.com/reference/android/hardware/Sensor#TYPE_MAGNETIC_FIELD_UNCALIBRATED) sensors provide raw sensor data without consideration for bias estimations. That is, the existing [TYPE_GYROSCOPE](https://developer.android.com/reference/android/hardware/Sensor#TYPE_GYROSCOPE) and [TYPE_MAGNETIC_FIELD](https://developer.android.com/reference/android/hardware/Sensor#TYPE_MAGNETIC_FIELD) sensors provide sensor data that takes into account estimated bias from gyro-drift and hard iron in the device, respectively. Whereas the new "uncalibrated" versions of these sensors instead provide the raw sensor data and offer the estimated bias values separately. These sensors allow you to provide your own custom calibration for the sensor data by enhancing the estimated bias with external data.

## Notification Listener

- Android 4.3 adds a new service class, [NotificationListenerService](https://developer.android.com/reference/android/service/notification/NotificationListenerService), that allows your app to receive information about new notifications as they are posted by the system.
- If your app currently uses the accessibility service APIs to access system notifications, you should update your app to use these APIs instead.

## Contacts Provider

### Query for "contactables"

- The new Contacts Provider query, [Contactables.CONTENT_URI](https://developer.android.com/reference/android/provider/ContactsContract.CommonDataKinds.Contactables#CONTENT_URI), provides an efficient way to get one [Cursor](https://developer.android.com/reference/android/database/Cursor) that contains all email addresses and phone numbers belonging to all contacts matching the specified query.

### Query for contacts deltas

- New APIs have been added to Contacts Provider that allow you to efficiently query recent changes to the contacts data. Previously, your app could be notified when something in the contacts data changed, but you would not know exactly what changed and would need to retrieve all contacts then iterate through them to discover the change.
- To track changes to inserts and updates, you can now include the [CONTACT_LAST_UPDATED_TIMESTAMP](https://developer.android.com/reference/android/provider/ContactsContract.ContactsColumns#CONTACT_LAST_UPDATED_TIMESTAMP) parameter with your selection to query only the contacts that have changed since the last time you queried the provider.
- To track which contacts have been deleted, the new table [ContactsContract.DeletedContacts](https://developer.android.com/reference/android/provider/ContactsContract.DeletedContacts) provides a log of contacts that have been deleted (but each contact deleted is held in this table for a limited time). Similar to [CONTACT_LAST_UPDATED_TIMESTAMP](https://developer.android.com/reference/android/provider/ContactsContract.ContactsColumns#CONTACT_LAST_UPDATED_TIMESTAMP), you can use the new selection parameter, [CONTACT_DELETED_TIMESTAMP](https://developer.android.com/reference/android/provider/ContactsContract.DeletedContactsColumns#CONTACT_DELETED_TIMESTAMP) to check which contacts have been deleted since the last time you queried the provider. The table also contains the constant [DAYS_KEPT_MILLISECONDS](https://developer.android.com/reference/android/provider/ContactsContract.DeletedContacts#DAYS_KEPT_MILLISECONDS) containing the number of days (in milliseconds) that the log will be kept.
- Additionally, the Contacts Provider now broadcasts the [CONTACTS_DATABASE_CREATED](https://developer.android.com/reference/android/provider/ContactsContract.Intents#CONTACTS_DATABASE_CREATED) action when the user clears the contacts storage through the system settings menu, effectively recreating the Contacts Provider database. It's intended to signal apps that they need to drop all the contact information they've stored and reload it with a new query.
- For sample code using these APIs to check for changes to the contacts, look in the ApiDemos sample available in the [SDK Samples](https://developer.android.com/tools/samples) download.

## Localization

### Improved support for bi-directional text

- Previous versions of Android support right-to-left (RTL) languages and layout, but sometimes don't properly handle mixed-direction text. So Android 4.3 adds the [BidiFormatter](https://developer.android.com/reference/android/text/BidiFormatter) APIs that help you properly format text with opposite-direction content without garbling any parts of it.
- For example, when you want to create a sentence with a string variable, such as "Did you mean 15 Bay Street, Laurel, CA?", you normally pass a localized string resource and the variable to [String.format()](https://developer.android.com/reference/java/lang/String#format(java.lang.String, java.lang.Object...)):  

### Kotlin

```kotlin
val suggestion = String.format(resources.getString(R.string.did_you_mean), address)
```

### Java

```java
Resources res = getResources();
String suggestion = String.format(res.getString(R.string.did_you_mean), address);
```
- However, if the locale is Hebrew, then the formatted string comes out like this:
- האם התכוונת ל 15 Bay Street, Laurel, CA?
- That's wrong because the "15" should be left of "Bay Street." The solution is to use [BidiFormatter](https://developer.android.com/reference/android/text/BidiFormatter) and its [unicodeWrap()](https://developer.android.com/reference/android/text/BidiFormatter#unicodeWrap(java.lang.String)) method. For example, the code above becomes:  

### Kotlin

```kotlin
val bidiFormatter = BidiFormatter.getInstance()
val suggestion = String.format(
        resources.getString(R.string.did_you_mean),
        bidiFormatter.unicodeWrap(address)
)
```

### Java

```java
Resources res = getResources();
BidiFormatter bidiFormatter = BidiFormatter.getInstance();
String suggestion = String.format(res.getString(R.string.did_you_mean),
        bidiFormatter.unicodeWrap(address));
```
- By default, [unicodeWrap()](https://developer.android.com/reference/android/text/BidiFormatter#unicodeWrap(java.lang.String)) uses the first-strong directionality estimation heuristic, which can get things wrong if the first signal for text direction does not represent the appropriate direction for the content as a whole. If necessary, you can specify a different heuristic by passing one of the [TextDirectionHeuristic](https://developer.android.com/reference/android/text/TextDirectionHeuristic) constants from [TextDirectionHeuristics](https://developer.android.com/reference/android/text/TextDirectionHeuristics) to [unicodeWrap()](https://developer.android.com/reference/android/text/BidiFormatter#unicodeWrap(java.lang.String, android.text.TextDirectionHeuristic)).
- **Note:** These new APIs are also available for previous versions of Android through the Android [Support
  Library](https://developer.android.com/tools/support-library), with the [BidiFormatter](https://developer.android.com/reference/android/support/v4/text/BidiFormatter) class and related APIs.

## Accessibility Services

### Handle key events

- An [AccessibilityService](https://developer.android.com/reference/android/accessibilityservice/AccessibilityService) can now receive a callback for key input events with the [onKeyEvent()](https://developer.android.com/reference/android/accessibilityservice/AccessibilityService#onKeyEvent(android.view.KeyEvent)) callback method. This allows your accessibility service to handle input for key-based input devices such as a keyboard and translate those events to special actions that previously may have been possible only with touch input or the device's directional pad.

### Select text and copy/paste

- The [AccessibilityNodeInfo](https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo) now provides APIs that allow an [AccessibilityService](https://developer.android.com/reference/android/accessibilityservice/AccessibilityService) to select, cut, copy, and paste text in a node.
- To specify the selection of text to cut or copy, your accessibility service can use the new action, [ACTION_SET_SELECTION](https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo#ACTION_SET_SELECTION), passing with it the selection start and end position with [ACTION_ARGUMENT_SELECTION_START_INT](https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo#ACTION_ARGUMENT_SELECTION_START_INT) and [ACTION_ARGUMENT_SELECTION_END_INT](https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo#ACTION_ARGUMENT_SELECTION_END_INT). Alternatively you can select text by manipulating the cursor position using the existing action, [ACTION_NEXT_AT_MOVEMENT_GRANULARITY](https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo#ACTION_NEXT_AT_MOVEMENT_GRANULARITY) (previously only for moving the cursor position), and adding the argument [ACTION_ARGUMENT_EXTEND_SELECTION_BOOLEAN](https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo#ACTION_ARGUMENT_EXTEND_SELECTION_BOOLEAN).
- You can then cut or copy with [ACTION_CUT](https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo#ACTION_CUT), [ACTION_COPY](https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo#ACTION_COPY), then later paste with [ACTION_PASTE](https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo#ACTION_PASTE).
- **Note:** These new APIs are also available for previous versions of Android through the Android [Support
  Library](https://developer.android.com/tools/support-library), with the [AccessibilityNodeInfoCompat](https://developer.android.com/reference/android/support/v4/view/accessibility/AccessibilityNodeInfoCompat) class.

### Declare accessibility features

- Beginning with Android 4.3, an accessibility service must declare accessibility capabilities in its metadata file in order to use certain accessibility features. If the capability is not requested in the metadata file, then the feature will be a no-op. To declare your service's accessibility capabilities, you must use XML attributes that correspond to the various "capability" constants in the [AccessibilityServiceInfo](https://developer.android.com/reference/android/accessibilityservice/AccessibilityServiceInfo) class.
- For example, if a service does not request the [flagRequestFilterKeyEvents](https://developer.android.com/reference/android/R.styleable#AccessibilityService_canRequestFilterKeyEvents) capability, then it will not receive key events.

## Testing and Debugging

### Automated UI testing

- The new [UiAutomation](https://developer.android.com/reference/android/app/UiAutomation) class provides APIs that allow you to simulate user actions for test automation. By using the platform's [AccessibilityService](https://developer.android.com/reference/android/accessibilityservice/AccessibilityService) APIs, the [UiAutomation](https://developer.android.com/reference/android/app/UiAutomation) APIs allow you to inspect the screen content and inject arbitrary keyboard and touch events.
- To get an instance of [UiAutomation](https://developer.android.com/reference/android/app/UiAutomation), call [Instrumentation.getUiAutomation()](https://developer.android.com/reference/android/app/Instrumentation#getUiAutomation()). In order for this to work, you must supply the `-w` option with the `instrument` command when running your [InstrumentationTestCase](https://developer.android.com/reference/android/test/InstrumentationTestCase) from [`adb shell`](https://developer.android.com/tools/help/shell#am).
- With the [UiAutomation](https://developer.android.com/reference/android/app/UiAutomation) instance, you can execute arbitrary events to test your app by calling [executeAndWaitForEvent()](https://developer.android.com/reference/android/app/UiAutomation#executeAndWaitForEvent(java.lang.Runnable, android.app.UiAutomation.AccessibilityEventFilter, long)), passing it a [Runnable](https://developer.android.com/reference/java/lang/Runnable) to perform, a timeout period for the operation, and an implementation of the [UiAutomation.AccessibilityEventFilter](https://developer.android.com/reference/android/app/UiAutomation.AccessibilityEventFilter) interface. It's within your [UiAutomation.AccessibilityEventFilter](https://developer.android.com/reference/android/app/UiAutomation.AccessibilityEventFilter) implementation that you'll receive a call that allows you to filter the events that you're interested in and determine the success or failure of a given test case.
- To observe all the events during a test, create an implementation of [UiAutomation.OnAccessibilityEventListener](https://developer.android.com/reference/android/app/UiAutomation.OnAccessibilityEventListener) and pass it to [setOnAccessibilityEventListener()](https://developer.android.com/reference/android/app/UiAutomation#setOnAccessibilityEventListener(android.app.UiAutomation.OnAccessibilityEventListener)). Your listener interface then receives a call to [onAccessibilityEvent()](https://developer.android.com/reference/android/app/UiAutomation.OnAccessibilityEventListener#onAccessibilityEvent(android.view.accessibility.AccessibilityEvent)) each time an event occurs, receiving an [AccessibilityEvent](https://developer.android.com/reference/android/view/accessibility/AccessibilityEvent) object that describes the event.
- There is a variety of other operations that the [UiAutomation](https://developer.android.com/reference/android/app/UiAutomation) APIs expose at a very low level to encourage the development of UI test tools such as [uiautomator](https://developer.android.com/tools/help/uiautomator). For instance, [UiAutomation](https://developer.android.com/reference/android/app/UiAutomation) can also:
  - Inject input events
  - Change the orientation of the screen
  - Take screenshots
- And most importantly for UI test tools, the [UiAutomation](https://developer.android.com/reference/android/app/UiAutomation) APIs work across application boundaries, unlike those in [Instrumentation](https://developer.android.com/reference/android/app/Instrumentation).

### Systrace events for apps

- Android 4.3 adds the [Trace](https://developer.android.com/reference/android/os/Trace) class with two static methods, [beginSection()](https://developer.android.com/reference/android/os/Trace#beginSection(java.lang.String)) and [endSection()](https://developer.android.com/reference/android/os/Trace#endSection()), which allow you to define blocks of code to include with the systrace report. By creating sections of traceable code in your app, the systrace logs provide you a much more detailed analysis of where slowdown occurs within your app.
- For information about using the Systrace tool, read [Analyzing Display and Performance with Systrace](https://developer.android.com/tools/debugging/systrace).

## Security

### Android key store for app-private keys

- Android now offers a custom Java Security Provider in the [KeyStore](https://developer.android.com/reference/java/security/KeyStore) facility, called Android Key Store, which allows you to generate and save private keys that may be seen and used by only your app. To load the Android Key Store, pass `"AndroidKeyStore"` to [KeyStore.getInstance()](https://developer.android.com/reference/java/security/KeyStore#getInstance(java.lang.String)).
- To manage your app's private credentials in the Android Key Store, generate a new key with [KeyPairGenerator](https://developer.android.com/reference/java/security/KeyPairGenerator) with [KeyPairGeneratorSpec](https://developer.android.com/reference/android/security/KeyPairGeneratorSpec). First get an instance of [KeyPairGenerator](https://developer.android.com/reference/java/security/KeyPairGenerator) by calling [getInstance()](https://developer.android.com/reference/java/security/KeyPairGenerator#getInstance(java.lang.String)). Then call [initialize()](https://developer.android.com/reference/java/security/KeyPairGenerator#initialize(int)), passing it an instance of [KeyPairGeneratorSpec](https://developer.android.com/reference/android/security/KeyPairGeneratorSpec), which you can get using [KeyPairGeneratorSpec.Builder](https://developer.android.com/reference/android/security/KeyPairGeneratorSpec.Builder). Finally, get your [KeyPair](https://developer.android.com/reference/java/security/KeyPair) by calling [generateKeyPair()](https://developer.android.com/reference/java/security/KeyPairGenerator#generateKeyPair()).

### Hardware credential storage

- Android also now supports hardware-backed storage for your [KeyChain](https://developer.android.com/reference/android/security/KeyChain) credentials, providing more security by making the keys unavailable for extraction. That is, once keys are in a hardware-backed key store (Secure Element, TPM, or TrustZone), they can be used for cryptographic operations but the private key material cannot be exported. Even the OS kernel cannot access this key material. While not all Android-powered devices support storage on hardware, you can check at runtime if hardware-backed storage is available by calling [KeyChain.IsBoundKeyAlgorithm()](https://developer.android.com/reference/android/security/KeyChain#isBoundKeyAlgorithm(java.lang.String)).

## Manifest Declarations

### Declarable required features

- The following values are now supported in the [`<uses-feature>`](https://developer.android.com/guide/topics/manifest/uses-feature-element) element so you can ensure that your app is installed only on devices that provide the features your app needs.

[FEATURE_APP_WIDGETS](https://developer.android.com/reference/android/content/pm/PackageManager#FEATURE_APP_WIDGETS)
:   Declares that your app provides an app widget and should be installed only on devices that
    include a Home screen or similar location where users can embed app widgets.
    Example:  

    ```scdoc
    <uses-feature android:name="android.software.app_widgets" android:required="true" />
    ```

[FEATURE_HOME_SCREEN](https://developer.android.com/reference/android/content/pm/PackageManager#FEATURE_HOME_SCREEN)
:   Declares that your app behaves as a Home screen replacement and should be installed only on
    devices that support third-party Home screen apps.
    Example:  

    ```scdoc
    <uses-feature android:name="android.software.home_screen" android:required="true" />
    ```

[FEATURE_INPUT_METHODS](https://developer.android.com/reference/android/content/pm/PackageManager#FEATURE_INPUT_METHODS)
:   Declares that your app provides a custom input method (a keyboard built with [InputMethodService](https://developer.android.com/reference/android/inputmethodservice/InputMethodService)) and should be installed only on devices that
    support third-party input methods.
    Example:  

    ```scdoc
    <uses-feature android:name="android.software.input_methods" android:required="true" />
    ```

[FEATURE_BLUETOOTH_LE](https://developer.android.com/reference/android/content/pm/PackageManager#FEATURE_BLUETOOTH_LE)
:   Declares that your app uses Bluetooth Low Energy APIs and should be installed only on devices
    that are capable of communicating with other devices via Bluetooth Low Energy.
    Example:  

    ```scdoc
    <uses-feature android:name="android.software.bluetooth_le" android:required="true" />
    ```

### User permissions

- The following values are now supported in the [`<uses-permission>`](https://developer.android.com/guide/topics/manifest/uses-permission-element) to declare the permissions your app requires in order to access certain APIs.

[BIND_NOTIFICATION_LISTENER_SERVICE](https://developer.android.com/reference/android/Manifest.permission#BIND_NOTIFICATION_LISTENER_SERVICE)
:   Required to use the new [NotificationListenerService](https://developer.android.com/reference/android/service/notification/NotificationListenerService) APIs.

[SEND_RESPOND_VIA_MESSAGE](https://developer.android.com/reference/android/Manifest.permission#SEND_RESPOND_VIA_MESSAGE)
:   Required to receive the [ACTION_RESPOND_VIA_MESSAGE](https://developer.android.com/reference/android/telephony/TelephonyManager#ACTION_RESPOND_VIA_MESSAGE)
    intent.
- For a detailed view of all API changes in Android 4.3, see the [API Differences Report](https://developer.android.com/sdk/api_diff/18/changes).