ADK 2012 is the latest version you can use to develop amazing accessories for Android-powered devices. This library only works as a wrapper of all ADK features for your Android app. If you want to see how ADK 2012 works, follow official documentation.


Even if this library is a wrapper and supports Android API level 10, I will only target API level 12 in this documentation as stated in cutting down backward support issue.


This library is available in MavenCentral repository and its deployment flow is based on SonaType Nexus repository. To use the library simply configure your Gradle or Maven dependencies as follows:


dependencies {
    compile 'me.palazzetti:adktoolkit:0.2.0'



Android Manifest

Create res/xml/usb_accessory_filter.xml configuration file to identify your accessory:

        manufacturer="Example, Inc."/>

Declare in your manifest that your application requires USB accessory support:

    <uses-feature android:name="android.hardware.usb.accessory" android:required="true"/>

    <!-- ... -->

Then add in your activity block this ADK intent filter:

    <!-- ... -->

    <!-- Adk Intent Filter -->
        <action android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED" />

    <meta-data android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED"

Android code

To use this toolkit initialize the AdkManager in your Activity during onCreate() method:

private AdkManager mAdkManager;

protected void onCreate(Bundle savedInstanceState) {

    mAdkManager = new AdkManager((UsbManager) getSystemService(Context.USB_SERVICE));

If you need to register a BroadcastReceiver to catch UsbManager.ACTION_USB_ACCESSORY_DETACHED action, you can use library default implementation as follows (always in your onCreate() method):

registerReceiver(mAdkManager.getUsbReceiver(), mAdkManager.getDetachedFilter());

Starting and stopping ADK listener

When you initialize an AdkManager, it just create a connection object between your device and your accessory. You need to start/stop AOA communication when you open/close your activity. Add these calls in your onResume() and onPause() methods:

protected void onPause() {

protected void onResume() {


If you need to leave the activity without stopping the communication, you can avoid mAdkManager.close(). However don’t forget to close the communication with a widget or a button in your activity so users can disable the accessory when they want. This avoid useless battery consumption.

Write and read serial text

As I write in my unittest, you can simply:

adkManager.writeSerial("Hello world!");
String readValue = adkManager.readSerial();
assertEquals("Hello world!", readValue);
// Not bad! :)

writeSerial() allows you to write a single char or a String object.

readSerial() read a single char or a String object until there are bytes to read in the buffer


readSerial() could be a long-running task (ex: you want to continuously read data from a thermal sensor). In this case, put readSerial() call inside a Service or an AsyncTask and don’t run this in your UI main thread.