1. Inside the note. Is the code that Samsung devices may not support and need to be replaced.
2.mUsbManager. Getsystemservice (Context.usb_service) was obtained.
3. Picked from the StackOverflow. The source address could not be found.
protected static final int std_usb_request_get_descriptor = 0x06;
Http://libusb.sourceforge.net/api-1.0/group__desc.html
protected static final int libusb_dt_string = 0x03;
Public String Getusbname () {
String strusbname = null;
hashmap<string, usbdevice> devicelist = Musbmanager.getdevicelist ();
if (devicelist.size () = = 0) {
return strusbname;
}
iterator<usbdevice> deviceiterator = Devicelist.values (). Iterator ();
if (Deviceiterator.hasnext ()) {
Usbdevice device = (usbdevice) deviceiterator.next ();
Strusbname = Device.getdevicename ();
LOG.D ("", "Name:" + device.getdevicename () + "\ n"
+ "VID:" + Device.getvendorid ()
+ "PID:" + Device.getproductid ());
Usbinterface intf = device.getinterface (0);
int EPC = 0;
EPC = Intf.getendpointcount ();
LOG.D ("", "Endpoints:" + EPC + "\ n");
LOG.D ("", "Permission:" + boolean.tostring (musbmanager.haspermission (device)) + "\ n");
Usbdeviceconnection connection = Musbmanager.opendevice (device);
if (null==connection) {
LOG.D ("", "(Unable to establish connection) \ n");
} else {
Claims exclusive access to a usbinterface.
This must is done before sending or receiving data on
Any usbendpoints belonging to the interface.
Connection.claiminterface (intf, true);
Getrawdescriptors can used to access descriptors
Not supported directly via the higher level APIs,
Like getting the manufacturer and product names.
Because it returns bytes, you can get a variety of
Different data types.
byte[] Rawdescs = Connection.getrawdescriptors ();
String manufacturer = "", Product = "";
Try
{
byte[] buffer = new byte[255];
int idxman = rawdescs[14];
int IDXPRD = rawdescs[15];
int rdo = Connection.controltransfer (usbconstants.usb_dir_in
| Usbconstants.usb_type_standard, Std_usb_request_get_descriptor,
(libusb_dt_string << 8) | Idxman, 0, buffer, 0xFF, 0);
Manufacturer = new String (buffer, 2, rdo-2, "Utf-16le");
RDO = Connection.controltransfer (usbconstants.usb_dir_in
| Usbconstants.usb_type_standard, Std_usb_request_get_descriptor,
(libusb_dt_string << 8) | IDXPRD, 0, buffer, 0xFF, 0);
Product = new String (buffer, 2, rdo-2, "Utf-16le");
/* int rdo = Connection.controltransfer (usbconstants.usb_dir_in
| Usbconstants.usb_type_standard, Std_usb_request_get_descriptor,
(libusb_dt_string << 8) | Idxman, 0x0409, buffer, 0xFF, 0); */
} catch (Unsupportedencodingexception e)
{
E.printstacktrace ();
}
LOG.D ("", "Manufacturer:" + manufacturer + "\ n");
LOG.D ("", "Product:" + product + "\ n");
LOG.D ("", "serial#:" + connection.getserial () + "\ n");
}
}
return strusbname;
}
Android Gets the name of the USB device