Tuesday, October 22, 2013

API Overview

API Overview


Android 2.3.4 provides the same framework API to applications as Android 2.3.3 (API level 10). For a summary of the API, see the Android 2.3.3 version notes.

Open Accessory Library


Open Accessory is a new capability for integrating connected peripherals with applications running on the platform. The capability is based on a USB (Universal Serial Bus) stack built into the platform and an API exposed to applications. Peripherals that attach to Android-powered devices as accessories connect as USB hosts.
Open Accessory is introduced in Android 3.1 (API level 12), but is made available to devices running Android 2.3.4 by means of an optional external library, the Open Accessory Library. The library exposes a framework API that lets applications discover, communicate with, and manage a variety of device types connected over USB. It also provides the implementation of the API against parts of the Android platform that are not directly exposed to applications in Android 2.3.4.
The Open Accessory Library is optional on any given device. Device manufacturers may choose whether to include the Open Accessory Library in their products or exclude it. The library is forward-compatible with Android 3.1, so applications developed against Android 2.3.4 will run properly on devices running Android 3.1, if those devices support USB accessories.
The API provided by the Open Accessory Library is based on the Open Accessory API provided in Android 3.1. In most areas, you can use the same techniques and APIs. However, developing for the Open Accessory Library on Android 2.3.4 differs from the standard USB API in these ways:
  • Obtaining a UsbManager object — To obtain a UsbManager object when using the add-on library, use the helper method getInstance() rather than getSystemService() For example:
    UsbManager manager = UsbManager.getInstance(this);
  • Obtaining a UsbAccessory from a filtered intent — When you filter for a connected device or accessory with an intent filter, the UsbAccessory object is contained inside the intent that is passed to your application. If you are using the add-on library, you can get the UsbAccessory object in the following manner:
    UsbAccessory accessory = UsbManager.getAccessory(intent)
  • No USB host support — Android 2.3.4 and the Open Accessory Library do not support USB host mode (for example, through UsbDevice), although USB host mode is supported in Android 3.1. An Android-powered device running Android 2.3.4 can not function as a USB host. The library enables the Android-powered device to function as a peripheral only, with the connected accessory functioning as USB host (through UsbAccessory).
To develop apps using the Open Accessory Library, you need:
  • The latest version of the Android SDK tools
  • The latest version of the Google APIs add-on, which includes the library itself (for linking)
  • An actual hardware device running Android 2.3.4 (or Android 3.1) with USB accessories support, for runtime testing against connected devices
For a full discussion of how to develop applications that interact with USB accessories, please see the related developer documentation.
Additionally, developers can request filtering on Google Play, such that their applications are not available to users whose devices do not provide the appropriate accessory support. To request filtering, add the element below to the application manifest:
<uses-feature
  android:name="android.hardware.usb.accessory"
  android:required="true">

No comments:

Post a Comment