I'm trying to get how many bytes are available for reading on a AOA connection but when I call the available ()
method of FileInputStream
I get an IOException with the message: 'ioctl failed: EINVAL (Invalid argument)'
Note 1: I'm calling Java methods from C++ Using JNI
Note 2: If, instead of calling available()
method I try to read, it work's perfectly
What am I doing wrong? Is there another way to ask for available bytes before reading from the socket on an AOA connection?
This is the Java Code:
public int testConnection () throws Exception {
UsbManager usbManager = (UsbManager) this.context.getSystemService(Context.USB_SERVICE);
final UsbAccessory[] accessoryList = usbManager.getAccessoryList();
if (accessoryList == null || accessoryList.length == 0) {
return -1;
} else {
UsbAccessory usb = accessoryList[0];
try {
ParcelFileDescriptor fileDescriptor = usbManager.openAccessory(usb);
if (fileDescriptor != null) {
FileDescriptor fd = fileDescriptor.getFileDescriptor();
FileInputStream inStream = new FileInputStream(fd);
inStream.available ();
} else {
return -2;
}
} catch (IOException e) {
return -3;
} catch (Exception e) {
return -4;
}
}
return 0;
}
If you do a 'Ctrl' + 'Clic' on the
available
method, you will see that the method isn't available for Android targets. The implement is changed from bare native and always returns an Exception.