如何确定UsbRequest.queue(..)方法接收的字节长度是多少?字节、长度、方法、UsbRequest

2023-09-05 08:25:23 作者:献世 〃

我在安卓3.1的烦恼与UsbRequest类。

I have troubles with UsbRequest class in Android 3.1.

这是我的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();
}

数组的大小数据是4096,但确实接收的字节长度更小。

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?

感谢。

推荐答案

这是Android的一个错误。在受灾的版本,有没有解决方法,因为实现根本不通过长了起来。

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

这是固定在JB-MR1(API级别17起)。

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