Implementation of the basic interaction with the USB device through Android Open Accessory (AOA) protocol.
You can find examples of interaction with FT311D, Arduino and so on in the android-accessory-bootstrap repository.
Add it to your build.gradle with:
allprojects {
repositories {
maven { url "https://jitpack.io" }
}
}
and:
dependencies {
compile 'com.github.vldmkr:android-accessory-interface:{latest version}'
}
This is an abstract class that implements the basic interaction with the USB device connected as USB host through Android Open Accessory (AOA) protocol.
Not all devices can support accessory mode. Suitable devices can be filtered using an <uses-feature>
element in the AndroidManifest.
Communication with the code on the application level is carried out through the android.os.Handler. Posted item will be processed as soon as the message queue will be ready to do so. Although this does not guarantee high speed of android.os.Message processing, but it satisfies the requirements.
The methods create and destroy must be called from the appropriate antagonistic callbacks of the application's life cycle, such as android.app.Activity#onResume and android.app.Activity#onPause.
The methods getManufacturer, getModel, getVersion are used to identify the USB accessory and must be implemented in the extended class.
The callback method requires an override if the extended class does not use a communication android.os.Handler.
- Parameters:
communicationHandler
— android.os.Handler involved in the communication with application-level code. If it is null, messages are processed by the internal android.os.Handler and pushed to callback as a parameter.bufferSize
— Expected data size of the java.io.FileInputStream from the USB device.
This method finds and opens an attached USB accessory if the caller has permission to access the accessory. Otherwise, the corresponding runtime permission request will be sent.
- Parameters:
context
— android.content.Context for which the android.content.BroadcastReceiver will be registered.
This method closes the connection with USB accessory if it is attached.
- Parameters:
context
— Context, which is accepted in the create method.
If communicationHandler param of AccessoryInterface is null, messages are pushed to this callback.
- Parameters:
msg
— android.os.Message received after processing by internal android.os.Handler.
- Returns: The implementation must not return null, it is used to identify the USB accessory.
- Returns: The implementation must not return null, it is used to identify the USB accessory.
- Returns: The implementation must not return null, it is used to identify the USB accessory.
Send data to the USB device. java.nio.channels.FileChannel from the non-blocking IO package is used.
- Parameters:
data
— The data array to send.
Send data to the USB device. Blocking operation. java.io.FileOutputStream is used.
- Parameters:
data
— The data array to send.byteOffset
— The offset to the first byte of the data array to be send.byteCount
— The maximum number of bytes to send.
The documentation is built using Javadoc-to-Markdown