Android: communication with USB devices

Source: Internet
Author: User

Communicating with a USB device in Android

Http://gssdaily.com/forum/viewtopic.php? F = 17 & t = 96084

By
Jack» Sat Sep 29,201 2 pm

Communicating with a USB device in Android

Communication with a USB device can be either synchronous or asynchronous. in either case, You shoshould create a new thread on which to carry out all data transmissions, so you don't block the UI thread. to properly set up communication with a device, you need
To obtain the appropriate USB interface and USB endpoint of the device that you want to communicate on and send requests on this endpoint with a USB deviceconnection.

Code:
Select All
rivate Byte[] bytes
private static int TIMEOUT = 0;
private boolean forceClaim = true;

...

UsbInterface intf = device.getInterface(0);
UsbEndpoint endpoint = intf.getEndpoint(0);
UsbDeviceConnection connection = mUsbManager.openDevice(device);
connection.claimInterface(intf, forceClaim);
connection.bulkTransfer(endpoint, bytes, bytes.length, TIMEOUT); //do in another thread

Jack
Posts:425
Joined:Tue Nov 30,201 0 pm
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.