Sending data to Android device, immediately after connection to USB, results in timeout

539 Views Asked by At

I have the following use case:

  1. App is running on phone.
  2. User connects accessory to phone.
  3. Accessory puts phone in accessory mode.
  4. After reconnecting and opening the right USB endpoint, accessory immediately tries to send data to app.

At step 4, I get USB error 7: Transfer error on bulk endpoint: Operation timed out on the accessory. Presumably this happens because the app has not yet opened the InputStream.

What is the correct way to handle this situation?

2

There are 2 best solutions below

0
On BEST ANSWER

The solution turned out to be to increase the timeout for USB transfers. I'm using USB4Java, and it has a default timeout of 5 seconds. When the timeout was increased, it turned out that it took 15 seconds for the first transfer to complete. So I set it to 30 seconds.

2
On

As you are probably aware, USB is flaky at best so I'd be looking at problems with driver and/or restarting the host machine and phone. This is the only suggestion I have assuming the USB settings are good on device.

This StackOverflow Question has a lot of answers that are things that I'd look at, some are not as obvious like not using a USB3 port.