Is it possible and how to connect to USB devices from Android in a Go program?

327 views
Skip to first unread message

con...@theninjabunny.com

unread,
Aug 20, 2016, 7:32:48 PM8/20/16
to golang-nuts

I'm developing an Android app using Golang that make use of a USB device connected to the Android (on those that support the host mode). My app works great if the device is rooted and SELinux is in permissive, unfortunately that's not common at all.

To avoid that, you could open the USB device in Java (usbManager) and then pass the file descriptor to the NDK (Go) code. At this point, I'm not sure if it's possible at all, or the x/mobile code has to be modified, but I have no idea how to continue nor where to find more information on the topic.

Using gomobile/bind for the app

Óscar Giménez

unread,
Jul 9, 2021, 5:17:15 PM7/9/21
to golang-nuts
Hi,

Were you able to solve this issue?
I'm facing the same problem.
Any help would be appreciated.

Thanks

Marko Bencun

unread,
Oct 11, 2022, 8:23:09 AM10/11/22
to golang-nuts
Hi

In Go, define an interface for opening the device and writing to it.

Implement that interface in Java/Kotlin using the Android API for interfacing with USB.

I used this without any issues in the BitBoxApp, which is an Android App that communicates with the BitBox02 hardware wallet:

Go interface:


Java implementation:


Cheers
Reply all
Reply to author
Forward
0 new messages