Bluetooth Serial Ionic在Android设备上不起作用,但在IOS上起作用

问题描述 投票:0回答:1

我非常难过,因为我做了很多尝试,使我的应用在Android上运行良好。我在Vue.js中使用Ionic。该代码在IOS上运行良好,但正在返回(“无法在Android上连接到此设备”)

      this.bluetoothSerial.connect("XX:XX:XX:XX:XX:99").subscribe(
        () => {
          // this.test++
          this.bluetoothSerial.subscribeRawData().subscribe(
            data => this.dataWatt = decoder.decode(data),
            error => alert(error + '2')
          )
        },
        (error) => {
          alert(error)
        }
      )

我不使用blueSoth来扫描除BLE之外的所有设备。我不知道在做什么...

cordova ionic-framework bluetooth android-bluetooth
1个回答
0
投票

https://www.npmjs.com/package/cordova-plugin-bluetooth-serial#connect

根据bluetoothSerial文档:

连接

连接到蓝牙设备。bluetoothSerial.connect(macAddress_or_uuid,connectSuccess,connectFailure);

说明

功能连接连接到蓝牙设备。回调长时间运行。连接成功时将调用成功。如果连接失败,则调用失败;如果连接断开,则调用失败。错误消息传递到失败回调。

Android

对于Android,connect使用远程设备的MAC地址。

iOS

对于iOS,连接采用远程设备的UUID。 (可选)您可以传递一个空字符串,该插件将连接到第一个BLE外设。

Windows Phone

对于Windows Phone,连接使用远程设备的MAC地址。 MAC地址可以选择用括号括起来。例如(AA:BB:CC:DD:EE:FF)

参数

macAddress_or_uuid:远程设备的标识符。

connectSuccess:连接成功时调用的成功回调函数。

connectFailure:错误回调函数,在发生错误或连接断开时调用。

这里是文档参考以及文档参考。

即使Mac错误,也可能连接到iOS ...检查您是否正确输入了Android的远程地址或uuid。

© www.soinside.com 2019 - 2024. All rights reserved.