Learning how to enable or disable the Bluetooth service and add a device name is a basic Bluetooth management skill:
- Retrieve a BluetoothAdapter object with the getDefaultAdapter() method:
var adapter = webapis.bluetooth.getDefaultAdapter();
- Enable or disable the Bluetooth adapter using the setPowered() method:
/* Enable Bluetooth */ adapter.setPowered(true, function() { console.log("Bluetooth powered on successfully."); }); /* Disable Bluetooth */ adapter.setPowered(false, function() { webapis.application.exit(); });
Give the device a unique name by using the setName() method.
The name helps to recognize devices in a list of retrieved active devices.
adapter.setName(chatServerName);