Android supports a variety of USB peripherals and Android USB accessories through two modes: USB accessory and USB host. In USB
accessory mode, the external USB hardware act as the USB hosts. The different accessories might
include robotics controllers; docking stations; diagnostic and musical equipment; kiosks; card
readers; and much more. This gives Android-powered devices that do not have host capabilities the
ability to interact with USB hardware. Android USB accessories must be designed to work with
Android-powered devices and must adhere to the Android accessory communication protocol. In USB
host mode, the Android-powered device acts as the host. Examples of devices include digital
cameras, keyboards, mice, and game controllers. USB devices that are designed for a wide range of
applications and environments can still interact with Android applications that can correctly
communicate with the device.
Usb accessory is supported by devices with Android 2.3.4 or more versions. When an Android-powered device is in USB accessory mode, the attached Android USB accessory acts as the host, provides power to the USB bus, and enumerates connected devices.Although the USB accessory APIs were introduced to the platform in Android 3.1, they are also available in Android 2.3.4 using the Google APIs add-on library.
There are two usage differences between using the Google APIs add-on library and the platform APIs.
If you are using the add-on library, you must obtain the
Usb accessory is supported by devices with Android 2.3.4 or more versions. When an Android-powered device is in USB accessory mode, the attached Android USB accessory acts as the host, provides power to the USB bus, and enumerates connected devices.Although the USB accessory APIs were introduced to the platform in Android 3.1, they are also available in Android 2.3.4 using the Google APIs add-on library.
com.android.future.usb
: To support USB accessory mode in Android 2.3.4, the Google APIs add-on library includes the backported USB accessory APIs and they are contained in this namespace. This add-on library is a thin wrapper around theandroid.hardware.usb
accessory APIs and does not support USB host mode. If you want to support the widest range of devices that support USB accessory mode, use the add-on library and import this package. It is important to note that not all Android 2.3.4 devices are required to support the USB accessory feature. Each individual device manufacturer decides whether or not to support this capability, which is why you must declare it in your manifest file.android.hardware.usb
: This namespace contains the classes that support USB accessory mode in Android 3.1.
There are two usage differences between using the Google APIs add-on library and the platform APIs.
If you are using the add-on library, you must obtain the
UsbManager
object in the following manner:UsbManager manager = UsbManager.getInstance(this);
If you are not using the add-on library, you must obtain the UsbManager
object in the following manner:UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
When you filter for a connected 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 must obtain the UsbAccessory
object in the following manner:UsbAccessory accessory = UsbManager.getAccessory(intent);
If you are not using the add-on library, you must obtain the UsbAccessory
object in the following manner:UsbAccessory accessory = (UsbAccessory) intent.getParcelableExtra(UsbManager.EXTRA_ACCESSORY);
The following codes that is to be changed in Manifest file in order accomplish usb accessory
- Because not all Android-powered devices are guaranteed to support the USB accessory APIs,
include a
<uses-feature>
element that declares that your application uses theandroid.hardware.usb.accessory
feature. - If you are using the
add-on library,
add the
<uses-library>
element specifyingcom.android.future.usb.accessory
for the library. - Set the minimum SDK of the application to API Level 10 if you are using the add-on library
or 12 if you are using the
android.hardware.usb
package. -
If you want your application to be notified of an attached USB accessory, specify an
<intent-filter>
and<meta-data>
element pair for theandroid.hardware.usb.action.USB_ACCESSORY_ATTACHED
intent in your main activity. The<meta-data>
element points to an external XML resource file that declares identifying information about the accessory that you want to detect.
In the XML resource file, declare<usb-accessory>
elements for the accessories that you want to filter. Each<usb-accessory>
can have the following attributes: manufacturer
model
version
res/xml/
directory. The resource file name
(without the .xml extension) must be the same as the one you specified in the
<meta-data>
element.
No comments:
Post a Comment