Example usage for android.hardware.usb UsbManager openAccessory

List of usage examples for android.hardware.usb UsbManager openAccessory

Introduction

In this page you can find the example usage for android.hardware.usb UsbManager openAccessory.

Prototype

@RequiresFeature(PackageManager.FEATURE_USB_ACCESSORY)
public ParcelFileDescriptor openAccessory(UsbAccessory accessory) 

Source Link

Document

Opens a file descriptor for reading and writing data to the USB accessory.

Usage

From source file:nl.bennyjacobs.aapbridge.aap.UsbConnection.java

public UsbConnection(Context context, UsbManager usbManager, UsbAccessory accessory) throws IOException {
    mContext = context;//  w ww .  java  2s. c o  m
    mAccessory = accessory;

    mFileDescriptor = usbManager.openAccessory(accessory);
    if (mFileDescriptor == null) {
        throw new IOException("Could not open accessory");
    }

    FileDescriptor fd = mFileDescriptor.getFileDescriptor();
    mInputStream = new BufferedInputStream(new FileInputStream(fd));
    mOutputStream = new BufferedOutputStream(new FileOutputStream(fd));
    IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
    filter.addAction(UsbManager.ACTION_USB_ACCESSORY_DETACHED);
    //mContext.registerReceiver(mUsbReceiver, filter);
}