usbDemo/src/main/java/au/id/jms/usbaudio/UsbAudio.java
public boolean open(final Context context, final UsbDevice device) {
        if (context == null) {
            throw new NullPointerException("no Android Context");
        }
        if (device == null) {
            throw new NullPointerException("no USB device");
        }

        UsbManager manager = (UsbManager) context.getSystemService(Context.USB_SERVICE);
        if (manager != null) {
            int fd = 0;
            try {
                UsbDeviceConnection conn = manager.openDevice(device);
                fd = conn.getFileDescriptor();
            } catch (Exception e) {
                e.printStackTrace();
            }
            String[] name = device.getDeviceName().split("/");
            int busnum = 0;
            int devnum = 0;
            if (name != null && name.length > 2) {
                busnum = Integer.parseInt(name[name.length - 2]);
                devnum = Integer.parseInt(name[name.length - 1]);
            }
            return setup(device.getVendorId(), device.getProductId(), fd, busnum, devnum);
        }
        return false;
    }
/**
     * Open USB audio device.
     *
     * @param context Android Context
     * @param device  USB device
     */
Open USB audio device.
@param context Android Context
@param device  USB device
Open USB audio device . @param context Android Context @param device USB device
public boolean open(final Context context, final UsbDevice device) {
        if (context == null) {
            throw new NullPointerException("no Android Context");
        }
        if (device == null) {
            throw new NullPointerException("no USB device");
        }
        UsbManager manager = (UsbManager) context.getSystemService(Context.USB_SERVICE);
        if (manager != null) {
            int fd = 0;
            try {
                UsbDeviceConnection conn = manager.openDevice(device);
                fd = conn.getFileDescriptor();
            } catch (Exception e) {
                e.printStackTrace();
            }
            String[] name = device.getDeviceName().split("/");
            int busnum = 0;
            int devnum = 0;
            if (name != null && name.length > 2) {
                busnum = Integer.parseInt(name[name.length - 2]);
                devnum = Integer.parseInt(name[name.length - 1]);
            }
            return setup(device.getVendorId(), device.getProductId(), fd, busnum, devnum);
        }
        return false;
    }
public boolean open ( final Context context , final UsbDevice device ) { if ( context == null ) { throw new NullPointerException ( "no Android Context" ) ; } if ( device == null ) { throw new NullPointerException ( "no USB device" ) ; } UsbManager manager = ( UsbManager ) context . getSystemService ( Context . USB_SERVICE ) ; if ( manager != null ) { int fd = 0 ; try { UsbDeviceConnection conn = manager . openDevice ( device ) ; fd = conn . getFileDescriptor ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } String [ ] name = device . getDeviceName ( ) . split ( "/" ) ; int busnum = 0 ; int devnum = 0 ; if ( name != null && name . length > 2 ) { busnum = Integer . parseInt ( name [ name . length - 2 ] ) ; devnum = Integer . parseInt ( name [ name . length - 1 ] ) ; } return setup ( device . getVendorId ( ) , device . getProductId ( ) , fd , busnum , devnum ) ; } return false ; }
Open USB audio device.
Open USB audio device .