输入关键字或相关内容进行搜索
搜索:
发布问题
代码如下:
没有找到相关结果
W小姐
WiFi打印这个功能,我试了很久,目前准备不才要socket,用原生直接调用安卓系统提供的打印服务,另安装与打印机配套的服务插件,如果你研究出来了,可否po一下解决方案,很关注这个问题,谢谢哦~
laodadandan (作者)
main = plus.android.runtimeMainActivity(); BluetoothAdapter = plus.android.importClass("android.bluetooth.BluetoothAdapter"); UUID = plus.android.importClass("java.util.UUID"); uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");//不需要更改 BAdapter = BluetoothAdapter.getDefaultAdapter(); BAdapter.cancelDiscovery(); //停止扫描 if(macaddr==null){ device = BAdapter.getRemoteDevice('DC:0D:30:28:25:95'); }else{ device = BAdapter.getRemoteDevice(macaddr);//这里是蓝牙打印机的蓝牙地址 } plus.android.importClass(device); bluetoothSocket = device.createInsecureRfcommSocketToServiceRecord(uuid); plus.android.importClass(bluetoothSocket); function print(str) { if(!bluetoothSocket.isConnected()) { console.log('断开了,需要重新连接,连接中'); bluetoothSocket.connect(); } if(bluetoothSocket.isConnected()) { console.log('连接成功'); var outputStream = bluetoothSocket.getOutputStream(); plus.android.importClass(outputStream); var s = plus.android.importClass('java.lang.String'); var string = new s(is_login+' '+'桌号'+' '+str+'\n\n\n\n');//必须以创建字符串对象的形式创建对象,否则返回NULL var bytes = string.getBytes('gbk'); outputStream.write(0x1d); outputStream.write(0x21); outputStream.write(0x011); console.log(bytes); outputStream.write(bytes); outputStream.flush(); } else { console.log('fail'); } } 这段代码放在mui.plusReady(function(){})里面,然后用到的地方直接调用print()方法即可
2018-06-15 11:18
回复 laodadandan:谢谢哦,不好意思才看到回复
2018-06-25 11:15
shipengqian - 你好
请问你使用wifi打印能用吗?能得话麻烦贴下代码
该问题目前已经被锁定, 无法添加新回复
laodadandan (作者)
main = plus.android.runtimeMainActivity();
BluetoothAdapter = plus.android.importClass("android.bluetooth.BluetoothAdapter");
UUID = plus.android.importClass("java.util.UUID");
uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");//不需要更改
BAdapter = BluetoothAdapter.getDefaultAdapter();
BAdapter.cancelDiscovery(); //停止扫描
if(macaddr==null){
device = BAdapter.getRemoteDevice('DC:0D:30:28:25:95');
}else{
device = BAdapter.getRemoteDevice(macaddr);//这里是蓝牙打印机的蓝牙地址
}
plus.android.importClass(device);
bluetoothSocket = device.createInsecureRfcommSocketToServiceRecord(uuid);
plus.android.importClass(bluetoothSocket);
function print(str) {
if(!bluetoothSocket.isConnected()) {
console.log('断开了,需要重新连接,连接中');
bluetoothSocket.connect();
}
if(bluetoothSocket.isConnected()) {
console.log('连接成功');
var outputStream = bluetoothSocket.getOutputStream();
plus.android.importClass(outputStream);
var s = plus.android.importClass('java.lang.String');
var string = new s(is_login+' '+'桌号'+' '+str+'\n\n\n\n');//必须以创建字符串对象的形式创建对象,否则返回NULL
var bytes = string.getBytes('gbk');
outputStream.write(0x1d);
outputStream.write(0x21);
outputStream.write(0x011);
console.log(bytes);
outputStream.write(bytes);
outputStream.flush();
} else {
console.log('fail');
}
}
这段代码放在mui.plusReady(function(){})里面,然后用到的地方直接调用print()方法即可
2018-06-15 11:18
W小姐
回复 laodadandan:谢谢哦,不好意思才看到回复
2018-06-25 11:15