[英]Get Bluetooth status on Tizen Wearable
I'm creating a watch face for my Gear 2 Neo (using Tizen Wearable SDK
), and I've spent hours looking (with no luck) for a way to determine if the bluetooth is enabled or not (and if possible if it's connected). 我正在为我的Gear 2 Neo创建表盘(使用
Tizen Wearable SDK
),并且花了数小时(没有运气)寻找一种方法来确定是否启用了蓝牙(如果可能,是否已连接蓝牙) )。
I've tried looking at the Tizen.SystemInfo API
documents, but I can't find anything. 我尝试查看
Tizen.SystemInfo API
文档,但找不到任何东西。 I've even tried tizen.systeminfo.getPropertyValue();
我什至尝试过
tizen.systeminfo.getPropertyValue();
with "BLUETOOTH" / "NETWORK" as the property
name, but this doesn't work. 使用“ BLUETOOTH” /“ NETWORK”作为
property
名称,但这不起作用。 It seems the Tizen.Bluetooth
namespace isn't usable either. 看来
Tizen.Bluetooth
命名空间也不可用。
I know there must be a way, as I have seen several watch faces out there that are able to get the status. 我知道必须有一种方法,因为我已经看到那里有几个可以取得状态的表盘。
Is anyone able to help me out / point me in the right direction? 有谁能够帮助我/指出正确的方向?
Edit: 编辑:
Using tizen.bluetooth.getDefaultAdapter();
使用
tizen.bluetooth.getDefaultAdapter();
returns the following: "The application does not have the privilege to call this method" 返回以下内容:“应用程序无权调用此方法”
Yes, it is possible. 对的,这是可能的。
To get the bluetooth status, you need to first get the defaultAdapter using following API 要获取蓝牙状态,您需要首先使用以下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);
}
Don't forget to add the privilege in config.xml of your app. 不要忘记在应用程序的config.xml中添加特权。
<tizen:privilege name="http://tizen.org/privilege/bluetooth.gap"/>
Note: Whenever you try to use platform, you need to provide the corresponding privilege in your apps config.xml file 注意:无论何时尝试使用平台,都需要在应用程序的config.xml文件中提供相应的特权。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.