printing - Send plain text to an USB Printer in Android -
after reading question: android usb permissions dialog never appears , doing tests, have following problem :
i need print usb printer (only plain text), establish connection, dialog appears, don't after this. can me must in openport(adevice)?
this try:
................ if (musbmanager.haspermission(mdevice)){ final usbdeviceconnection mconnection = musbmanager.opendevice(mdevice); intf = mdevice.getinterface(0); (int = 0; < intf.getendpointcount(); i++) { usbendpoint ep = intf.getendpoint(i); if (ep.gettype() == usbconstants.usb_endpoint_xfer_bulk) { if (ep.getdirection() == usbconstants.usb_dir_out) { mendpointbulkout = ep; usbdeviceconnection connection = musbmanager.opendevice(mdevice); if(connection!=null) { log.e(tag," conectado"); } connection.claiminterface(intf, forceclaim); //integer res = connection.bulktransfer(mendpointbulkout, bytes, bytes.length, timeout); new thread(new runnable() { @override public void run() { // todo auto-generated method stub log.i(tag, "in run thread"); int b = mconnection.bulktransfer(mendpointbulkout, bytes, bytes.length, 100000); log.i(tag, "b-->" + b); } }).start(); connection.releaseinterface(intf); break; } } } } else musbmanager.requestpermission(mdevice, mpermissionintent); break;`
.......
mconnection.bulktransfer alwais return -1
your mconnection null thread , new thread doesn't have access usbdeviceconnection. rebuild application, follow usb host more or @ least try put mconnection in singleton.
also can try connect proxy application: net2usb
Comments
Post a Comment