12. ADK運作架構介紹
ADK於Android的API支援
Android 3.1 平板電腦作業系統已內建 Android Open
Accessory Development Kit ( ADK ) 的 Android Open
Accessory APIs ,並具備USB Host mode 。
Android 2.3.4 智慧型手機作業系統可以透過 Google APIs
附加函式庫 (Google APIs add-on library ) 的方式運作。)
USB Host and Accessory Mode
※USB Host Mode只在
Android
3.1以上版本支援
12
13. ADK運作架構介紹
USB Accessory API(android.hardware.usb)
Class Description
UsbManager Allows you to enumerate and communicate with connected
USB accessories.
UsbAccessory Represents a USB accessory and contains methods to access its
identifying information.
USB Host API(android.hardware.usb
Class Description
Allows you to enumerate and communicate with connected USB devices.
UsbManager
Represents a connected USB device and contains methods to access its identifying information,
UsbDevice interfaces, and endpoints.
Represents an interface of a USB device, which defines a set of functionality for the device. A device can
UsbInterface have one or more interfaces on which to communicate on.
Represents an interface endpoint, which is a communication channel for this interface. An interface can
UsbEndpoint have one or more endpoints, and usually has input and output endpoints for two-way communication
with the device.
Represents a connection to the device, which transfers data on endpoints. This class allows you to send
UsbDeviceConnection data back and forth sychronously or asynchronously.
Represents an asynchronous request to communicate with a device through a UsbDeviceConnection.
UsbRequest
Defines USB constants that correspond to definitions in linux/usb/ch9.h of the Linux kernel.
UsbConstants
13
40. 全雙工資料處理設計
替子執行緒產生Looper與MQ public static final void prepare() {
if (sThreadLocal.get() != null) {
throw new RuntimeException(
Class subThread implements Runnable{ "Only one Looper may be created
public void run(){ per thread");
}
Looper.prepare(); 框架原始碼
sThreadLocal.set(new Looper());
workLooper = Looper.myLooper(); }
h = new Handler(){
public handlerMessage(Message msg){
//處理message
}
};
private Looper() {
Looper.loop(); 框架原始碼 mQueue = new MessageQueue();
mRun = true;
} mThread = Thread.currentThread();
} }
40