在 Tizen Wearable 上获取蓝牙状态
Get Bluetooth status on Tizen Wearable
我正在为我的 Gear 2 Neo 创建一个表盘(使用 Tizen Wearable SDK
),我花了几个小时寻找(没有运气)确定蓝牙是否启用的方法(如果可能的话,如果它已连接)。
我试过查看 Tizen.SystemInfo API
文档,但找不到任何内容。我什至尝试过将 tizen.systeminfo.getPropertyValue();
与 "BLUETOOTH" / "NETWORK" 作为 property
名称,但这不起作用。 Tizen.Bluetooth
命名空间似乎也不可用。
我知道一定有办法,因为我看到有几个表盘可以获取状态。
有谁能帮助我/指出正确的方向吗?
编辑:
使用 tizen.bluetooth.getDefaultAdapter();
returns 以下内容:"The application does not have the privilege to call this method"
是的,有可能。
要获取蓝牙状态,您需要先使用以下方法获取默认适配器 API
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 文件
中提供相应的权限
我正在为我的 Gear 2 Neo 创建一个表盘(使用 Tizen Wearable SDK
),我花了几个小时寻找(没有运气)确定蓝牙是否启用的方法(如果可能的话,如果它已连接)。
我试过查看 Tizen.SystemInfo API
文档,但找不到任何内容。我什至尝试过将 tizen.systeminfo.getPropertyValue();
与 "BLUETOOTH" / "NETWORK" 作为 property
名称,但这不起作用。 Tizen.Bluetooth
命名空间似乎也不可用。
我知道一定有办法,因为我看到有几个表盘可以获取状态。
有谁能帮助我/指出正确的方向吗?
编辑:
使用 tizen.bluetooth.getDefaultAdapter();
returns 以下内容:"The application does not have the privilege to call this method"
是的,有可能。
要获取蓝牙状态,您需要先使用以下方法获取默认适配器 API
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 文件
中提供相应的权限