Example usage for android.hardware.usb UsbDeviceConnection getFileDescriptor

List of usage examples for android.hardware.usb UsbDeviceConnection getFileDescriptor

Introduction

In this page you can find the example usage for android.hardware.usb UsbDeviceConnection getFileDescriptor.

Prototype

public int getFileDescriptor() 

Source Link

Document

Returns the native file descriptor for the device, or -1 if the device is not opened.

Usage

From source file:marto.rtl_tcp_andro.DeviceOpenActivity.java

/**
 * Opens a certain USB device and prepares an argument to be passed to libusb
 * @param device/*from www.j a v a  2s  .co  m*/
 */
@SuppressLint("NewApi")
public void openDevice(final UsbDevice device) {
    final UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);

    if (device != null && !manager.hasPermission(device)) {
        android.util.Log.d("rtl_tcp_andro", "No permissions for device, requesting!");
        manager.requestPermission(device, permissionIntent);
        return;
    }

    if (device == null || !manager.hasPermission(device))
        finishWithError(err_info.permission_denied);

    final UsbDeviceConnection connection = manager.openDevice(device);

    if (connection == null)
        finishWithError(err_info.unknown_error);

    startBinary(arguments, connection.getFileDescriptor(), properDeviceName(device.getDeviceName()));
}

From source file:com.wordpress.ebc81.rtl_ais_android.DeviceOpenActivity.java

/**
 * Opens a certain USB device and prepares an argument to be passed to libusb
 * @param device//ww  w .  j a va 2s. c  o m
 */
//@SuppressLint("NewApi")
public void openDevice(final UsbDevice device) {
    final UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);

    if (device != null && !manager.hasPermission(device)) {
        android.util.Log.d("rtl_tcp_andro", "No permissions for device, requesting!");
        manager.requestPermission(device, permissionIntent);
        return;
    }

    if (device == null || !manager.hasPermission(device))
        finishWithError(err_info.permission_denied);

    final UsbDeviceConnection connection = manager.openDevice(device);

    if (connection == null)
        finishWithError(err_info.unknown_error);

    startBinary(arguments, connection.getFileDescriptor(), properDeviceName(device.getDeviceName()));
}