Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I determine the length of received bytes of UsbRequest.queue(..) method?

I have troubles with UsbRequest class in Android 3.1.

This is my code:

ByteBuffer buffer = ByteBuffer.allocate(4096);
buffer.order(ByteOrder.LITTLE_ENDIAN);
UsbRequest request = new UsbRequest();
request.initialize(mConnection, mEndpointIn);
request.queue(buffer, 4096);

if (mConnection.requestWait() == request) {
   byte[] data = buffer.array();
}

The size of array data is 4096, but the length of really received bytes is much more smaller.

How can i determine the size of really received bytes?

Thanks.

like image 213
Slava Avatar asked Aug 02 '11 16:08

Slava


Video Answer


1 Answers

This was a bug in Android. On afflicted versions, there's no workaround, because the implementation simply doesn't pass the length up.

It was fixed in JB-MR1 (API level 17 onwards).

like image 99
mik3y Avatar answered Sep 19 '22 12:09

mik3y