【问题标题】:Android bluethoot with printer adapter带打印机适配器的安卓蓝牙
【发布时间】:2013-12-29 19:03:45
【问题描述】:
我有问题。
我有一台蓝牙打印机适配器“Bluetake BT220”和一台打印机“Star DP8340S”。
我想将我的 bluetot bt220 连接到我的应用程序 android,我有其他连接到斑马打印机,但实现了连接。
对于这个适配器bluethoot,没有连接,上网找了很多,我看到我可以直接连接bluethoot。
我可以连接到设备,但无法在
有人可以告诉我从哪里开始吗?欢迎提出任何建议。
任何文档,请不要犹豫
谢谢大家,让生活更轻松。
【问题讨论】:
标签:
android
printing
bluetooth
android-bluetooth
【解决方案1】:
我自己回答。
已解决:我刚刚创建了一个 Connection bluethoot follow
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
BluetoothDevice bluetakebt220 = bluetoothAdapter.getRemoteDevice(obj.getMac().toString());
Method m;
BluetoothSocket mBTsocket= null;
m = bluetakebt220.getClass().getMethod("createRfcommSocket",
new Class[] { int.class });
// mBTsocket = (BluetoothSocket) m.invoke(bluetakebt220, 1);
UUID num = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
mBTsocket = bluetakebt220.createRfcommSocketToServiceRecord(num);
mBTsocket.connect();
现在只需要打印
String txt ="LINE 1 \n LINE 2 \n";
byte[] CPCLFormat = null;
try {
CPCLFormat = txt .getBytes("utf-8");
try {
os.write(CPCLFormat);
} catch (Exception e) {
os.close();
e.printStackTrace();
}
} catch (UnsupportedEncodingException e1) {
CPCLFormat = null;
os.close();
e1.printStackTrace();
}
os.close();
希望对你有帮助,谢谢