更新记录
1.0.0(2025-04-02)
经典蓝牙服务端
平台兼容性
App |
快应用 |
微信小程序 |
支付宝小程序 |
百度小程序 |
字节小程序 |
QQ小程序 |
HBuilderX 3.6.8,Android:4.4,iOS:不支持,HarmonyNext:不支持 |
× |
× |
× |
× |
× |
× |
钉钉小程序 |
快手小程序 |
飞书小程序 |
京东小程序 |
鸿蒙元服务 |
× |
× |
× |
× |
× |
H5-Safari |
Android Browser |
微信浏览器(Android) |
QQ浏览器(Android) |
Chrome |
IE |
Edge |
Firefox |
PC-Safari |
× |
× |
× |
× |
× |
× |
× |
× |
× |
经典蓝牙服务端
开发文档
- 拷贝demo的AndroidManifest.xml到项目根目录
- 集成插件步骤请参考 https://www.cnblogs.com/wenrisheng/p/18323027
接口
import {
UTSClassicsBtServer,
UTSBt
} from "@/uni_modules/wrs-uts-classicsbt"
let server = new UTSClassicsBtServer()
let isEnabled = UTSBt.isEnable()
if (!isEnabled) {
}
let suc = UTSBt.enable()
this.showMsg("打开蓝牙:" + suc)
let name = UTSBt.getName()
UTSBt.setName("XXXX")
server.onCallback((resp) => {
this.showMsg(JSON.stringify(resp))
let opt = resp.opt
switch (opt) {
case "onNewClient": {
//
let remoteDevice = resp.remoteDevice
// 蓝牙mac地址
let address = remoteDevice.address
this.showMsg("收到一个新连接:" + address)
}
break;
case "onReceiveData": {
let remoteDevice = resp.remoteDevice
let data = resp.data
this.showMsg("收到数据:" + JSON.stringify(data))
}
break;
case "onDisconnectClient": {
this.showMsg("连接被断开")
}
break;
default:
break;
}
})
let params = {}
params.name = "BTServer"
params.uuid = "00001101-0000-1000-8000-00805F9B34FB"
// secure
// true: 加密传输,Android强制执行配对,弹窗显示配对码
// false: 明文传输(不安全),无需配对
params.secure = false // true
server.startServer(params)
server.stopServer()
let address = "0x:xx"
server.disconnect(address)
let params = {}
params.address = "xxx"
params.data = [0x01, 0x02, 0x03] // 十六进制数组
server.sendData(params)