我正在为我的 Gear 2 Neo 创建表盘(使用 Tizen Wearable SDK
),并且我花了几个小时寻找(但没有运气)确定蓝牙是否可用的方法。是否启用(如果可能的话,如果已连接)。
我尝试查看 Tizen.SystemInfo API
文档,但找不到任何内容。我什至尝试过使用“BLUETOOTH”/“NETWORK”作为 property
名称,但这不起作用。看来 Tizen.Bluetooth
命名空间也不可用。
我知道一定有办法,因为我已经看到了几个能够获取状态的表盘。
有人能帮助我/为我指明正确的方向吗?
编辑:
使用 tizen.bluetooth.getDefaultAdapter();
返回以下内容:“应用程序没有调用此方法的权限”
最佳答案
是的,这是可能的。
要获取蓝牙状态,您需要首先使用以下API获取defaultAdapter
var blueAdapter = tizen.bluetooth.getDefaultAdapter();
console.log(blueAdapter); // To log the object
/* Output of above log
BluetoothAdapter
address: ""
name: ""
powered: false
visible: true
*/
if (blueAdapter.powered) {
// Bluetooth is on, you can off using
blueAdapter.setPowered(false);
} else {
// Bluetooth is off, you can switch on using
blueAdapter.setPowered(true);
}
不要忘记在应用程序的 config.xml 中添加权限。
<tizen:privilege name="http://tizen.org/privilege/bluetooth.gap"/>
注意:每当您尝试使用平台时,您需要在应用程序的 config.xml 文件中提供相应的权限
关于javascript - 获取 Tizen 可穿戴设备上的蓝牙状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30553111/