Nativescript - 本机android蓝牙低能量

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

我想知道为什么我无法在Nativescript中访问本机android蓝牙低能量,但我可以访问原生的android经典蓝牙。

const adapter = android.bluetooth.BluetoothAdapter;

上面的示例代码工作正常,而下面的示例代码不起作用。

const BleAdvertiser = android.bluetooth.le.BluetoothLeAdvertiser;

错误:“属性'le'在类型'typeof bluetooth'上不存在'”

有谁知道那是为什么?任何帮助都非常感谢。谢谢!

android bluetooth bluetooth-lowenergy nativescript android-bluetooth
1个回答
0
投票

我已经解决了这个问题!

对于可能遇到相同问题的任何人,请转到项目文件夹中的references.d.ts文件,该文件应包含类似的内容

/// <reference path="./node_modules/tns-platform-declarations/ios.d.ts" />
/// <reference path="./node_modules/tns-platform-declarations/android.d.ts" />

然后更新你的android.d.ts文件,其中应包含类似的内容

/// <reference path="./android-17.d.ts" />

将17更改为至少21,这些数字代表API级别。 API级别21或Android v5.0(Lollipop)支持Android原生蓝牙低功耗。

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