mui.plusReady(function(){
var main = plus.android.runtimeMainActivity();
var BluetoothAdapter = plus.android.importClass("android.bluetooth.BluetoothAdapter");
var UUID=plus.android.importClass("java.util.UUID");
uuid=UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
var BAdapter = BluetoothAdapter.getDefaultAdapter();
BAdapter.cancelDiscovery();//停止扫描
var addres_mac = plus.storage.getItem("printer");//传入打印机mac地址
device=BAdapter.getRemoteDevice(addres_mac);
plus.android.importClass(device);
});
function print(){
bluetoothSocket = device.createInsecureRfcommSocketToServiceRecord(uuid);
plus.android.importClass(bluetoothSocket);
if(!bluetoothSocket.isConnected()){
bluetoothSocket.connect();
}
var outputStream=bluetoothSocket.getOutputStream();
plus.android.importClass(outputStream);
var string="你好123";
var bytes = plus.android.invoke(string,'getBytes','gbk');
//console.log(bytes+"."+bytes.length);
outputStream.write(bytes);
outputStream.flush();
}
0 个回复