Skip to content Skip to sidebar Skip to footer

Android Usb Host Deviceconnection.setinterface Prior To Api Level 21

I have a USB device I need to communicate with, and I have the code working using NDK code using JNI calls to the USB host APIs. However it involves a call to DeviceConnection.setI

Solution 1:

I ended up resorting to native code to call the same usbfs code that UsbDeviceConnection.setInterface() does:

#include<linux/ioctl.h>#include<sys/ioctl.h>// Struct and ioctl define stolen from linux_usbfs.hstructusbfs_setinterface {
  /* keep in sync with usbdevice_fs.h:usbdevfs_setinterface */unsignedint interface;
  unsignedint altsetting;
};

#define IOCTL_USBFS_SETINTF _IOR('U', 4, struct usbfs_setinterface)// Basically the same as linux_usbfs.cint fd = gUsbDeviceConnection.getFileDescriptor(env);
structusbfs_setinterface setintf;

setintf.interface = CIMAX_INTERFACE;
setintf.altsetting = alternate;
int r = ioctl(fd, IOCTL_USBFS_SETINTF, &setintf);

Note that the gUsbDeviceConnection.getFileDescriptor(env); line is my JNI wrapper for calling the Java UsbDeviceConnection.getFileDescriptor method from C++ - your method may vary.

This worked for me on API 19 and 21.

Post a Comment for "Android Usb Host Deviceconnection.setinterface Prior To Api Level 21"