我正在使用以下代码通过安装在我的Samsung打印机上的USB线的
Android设备进行打印.
使用startPrinting方法时,它会在调试日志中给出以下验证:
>命令到打印机发送成功
>授予打印机许可.
并且打印机甚至开始发出哔哔声,但我提供的数据不会打印出来.我陷入了这个阶段,并没有找到谷歌或stackoverflow的帮助.
注意:没有崩溃也没有错误
我在Android Jelly bean 4.3操作系统上测试此代码
任何帮助,将不胜感激.
private UsbManager mUsbManager;
private UsbDevice mDevice;
private UsbDeviceConnection mConnection;
private UsbInterface mInterface;
private UsbEndpoint mEndPoint;
private PendingIntent mPermissionIntent;
private static final String ACTION_USB_PERMISSION = "com.android.example.USB_PERMISSION";
private static Boolean forceCLaim = true;
HashMap mDeviceList;
Iterator mDeviceIterator;
int protocol;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mUsbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
mDeviceList = mUsbManager.getDeviceList();
mDeviceIterator = mDeviceList.values().iterator();
Button print = (Button) findViewById(R.id.buttonPrint);
Toast.makeText(this, "Device List Size: " + String.valueOf(mDeviceList.size()), Toast.LENGTH_SHORT).show();
TextView textView = (TextView) findViewById(R.id.usbDevice);
String usbDevice = "";
// This is just testing what devices are connected
while (mDeviceIterator.hasNext())
{
UsbDevice usbDevice1 = mDeviceIterator.next();
usbDevice += "\n" + "DeviceID: " + usbDevice1.getDeviceId() + "\n" + "DeviceName: " + usbDevice1.getDeviceName() + "\n" + "DeviceClass: " + usbDevice1.getDeviceClass() + " - "
+ translateDeviceClass(usbDevice1.getDeviceClass()) + "\n" + "DeviceSubClass: " + usbDevice1.getDeviceSubclass() + "\n" + "VendorID: " &