的USB打印机阅读这个问题后:Android USB Permissions Dialog never appears和做一些测试,我有以下问题:发送纯文本到Android中
我需要打印到USB打印机太(纯文本),我建立连接,出现对话框,但我现在不会在此之后做什么。任何人都可以帮助我在openPort(aDevice)中做什么?
这是我尝试:
................
if (mUsbManager.hasPermission(mDevice)){
final UsbDeviceConnection mConnection = mUsbManager.openDevice(mDevice);
intf = mDevice.getInterface(0);
for (int i = 0; i < 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返回-1
你能做到吗? – 2013-11-10 01:22:01