Giter VIP home page Giter VIP logo

android-accessory-interface's Introduction

android-accessory-interface

Release

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.

Installation

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}'
}

Documentation

public abstract class AccessoryInterface

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.

protected AccessoryInterface(final Handler communicationHandler, final int bufferSize)

public final void create(final Context context)

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.

public final void destroy(final Context context)

This method closes the connection with USB accessory if it is attached.

  • Parameters: context — Context, which is accepted in the create method.

protected void callback(Message msg)

If communicationHandler param of AccessoryInterface is null, messages are pushed to this callback.

public abstract String getManufacturer()

  • Returns: The implementation must not return null, it is used to identify the USB accessory.

public abstract String getModel()

  • Returns: The implementation must not return null, it is used to identify the USB accessory.

public abstract String getVersion()

  • Returns: The implementation must not return null, it is used to identify the USB accessory.

protected final void write(byte[] data)

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.

protected final void directWrite(byte[] data, int byteOffset, int byteCount)

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

android-accessory-interface's People

Contributors

vldmkr avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.