java usb打印机_java – 打印使用USB线问题

本文探讨了在Android设备上使用Java通过USB连接Samsung打印机进行打印时遇到的问题。作者提供了相关代码,但发现数据无法成功打印,尽管打印机有响应。问题出现在数据传输阶段,但没有出现错误或崩溃。作者在Jelly Bean 4.3上测试了这段代码,并寻求解决方案。
摘要由CSDN通过智能技术生成

我正在使用以下代码通过安装在我的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: " &

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值