2

大佬们做过蓝牙打印吗 uniapp 里基于安卓的好像

 2 years ago
source link: https://www.v2ex.com/t/831112
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

V2EX  ›  程序员

大佬们做过蓝牙打印吗 uniapp 里基于安卓的好像

  qwertyzzz · 1 天前 · 674 次点击

但是目前 80%可以打印 20%的概率会出现打印机的蓝牙图标闪烁 但是打印不出来。。

var BluetoothAdapter = plus.android.importClass("android.bluetooth.BluetoothAdapter");
		var BAdapter = BluetoothAdapter.getDefaultAdapter();
		var UUID = plus.android.importClass("java.util.UUID");
		var uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
		var device = BAdapter.getRemoteDevice(bluetoothInfo.address);
		plus.android.importClass(device);
		var bluetoothSocket = device.createInsecureRfcommSocketToServiceRecord(uuid);
		plus.android.importClass(bluetoothSocket);
		if (!bluetoothSocket.isConnected()) {
			console.log(bluetoothSocket.isConnected())
			bluetoothSocket.connect()
			console.log('连接蓝牙')
			console.log(bluetoothSocket.isConnected())
			if (!bluetoothSocket.isConnected()) {
				return uni.$u.toast('蓝牙连接失败')
			}
		}

基本代码是这个 不过我每次打印都会调用一下这个代码 有的时候连续打也没问题


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK