I have a usb device connected to Android that when I press a button(located on the usb device) It sends a 'S' string. How can I detect such string?
When I connect the Usb device to windows, and open any text editor such notepad++ and press the button the 'S' string appears.
I have managed to connect with the device which is a camera and open it. But is there any way to detect when the button is pressed by receaving the string 'S'.
From documentation: USB Host
USB SERVICE contains a Service to isolate all Usb operations. It's a sample code to read from serial port:
String YOUR_DEVICE_NAME;
byte[] DATA;
int TIMEOUT;
USBManager manager = getApplicationContext().getSystemService(Context.USB_SERVICE);
Map<String, USBDevice> devices = manager.getDeviceList();
USBDevice mDevice = devices.get(YOUR_DEVICE_NAME);
USBDeviceConnection connection = manager.openDevice(mDevice);
USBEndpoint endpoint = device.getInterface(0).getEndpoint(0);
connection.claimInterface(device.getInterface(0), true);
connection.bulkTransfer(endpoint, DATA, DATA.length, TIMEOUT);
Hope it helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.