androidusbandroid-open-accessory

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


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?


Solution

  • 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.