【问题标题】:Bluetooth Serial Ionic don't work on Android device but working on IOS蓝牙 Serial Ionic 不适用于 Android 设备,但适用于 IOS
【发布时间】:2020-01-17 14:12:31
【问题描述】:

我很伤心,因为我尝试了很多方法来让我的应用在 android 上运行良好。 我将 Ionic 与 Vue.js 一起使用。代码在 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)
        }
      )

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

【问题讨论】:

    标签: cordova ionic-framework bluetooth android-bluetooth


    【解决方案1】:

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

    根据蓝牙串口文档:

    连接

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

    说明

    函数 connect 连接到蓝牙设备。回调长时间运行。连接成功时会调用success。如果连接失败,则调用失败,如果连接断开,则稍后调用。错误消息被传递给失败回调。

    安卓

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

    iOS

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

    Windows 手机

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

    参数

    macAddress_or_uuid:远程设备的标识符。

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

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

    除了文档参考之外,这里还有文档的预览。

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

    【讨论】:

      猜你喜欢
      • 2023-03-10
      • 1970-01-01
      • 1970-01-01
      • 2023-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-30
      • 1970-01-01
      相关资源
      最近更新 更多