android 蓝牙打印框架,Android蓝牙打印

我正在编写一个将数据发送到蓝牙打印机的应用程序.谁能帮我 ?如何使用Android蓝牙堆栈进行打印?或者是否有任何外部api或sdk使用?

这是我搜索蓝牙的代码...

bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

registerReceiver(ActionFoundReceiver,

new IntentFilter(BluetoothDevice.ACTION_FOUND));

private final BroadcastReceiver ActionFoundReceiver = new BroadcastReceiver() {

@Override

public void onReceive(Context context, Intent intent) {

String action = intent.getAction();

if (BluetoothDevice.ACTION_FOUND.equals(action)) {

BluetoothDevice device = intent

.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);

btArrayAdapter.add(device.getName() + "\n"

+ device.getAddress());

btArrayAdapter.notifyDataSetChanged();

}

}

};

这是我的数据发送到打印机的代码..

BluetoothDevice mDevice = bluetoothAdapter.getRemoteDevice("00:15:FF:F2:56:A4");

Method m = mDevice.getClass().getMethod("createRfcommSocket",

new Class[] { int.class });

mBTsocket = (BluetoothSocket) m.invoke(mDevice, 1);

System.out.println("Connecting.....");

mBTsocket.connect();

System.out.println("Connected");

OutputStream os = mBTsocket.getOutputStream();

os.flush();

os.write(Receipt.getBytes());

// mBTsocket.close();

当我写socket.close()时,数据没有打印到打印机,因为套接字连接在打印数据之前关闭..如果我没有写socket.close()那么数据只打印一次..我不会能够第二次打印数据,直到我重新启动手机的蓝牙.

任何人都可以解决它?还是有其他方法可以摆脱这种印刷?

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值