This plugin enable to check if bluetooth is enabled or disabled.
- Android
Install with Cordova cli
$ cordova plugin add https://github.com/engbmsdev/BluetoothSerial
Reports if bluetooth is enabled.
bluetoothState.isEnabled(success, failure);
Function isEnabled
calls the success callback when bluetooth is enabled and the failure callback when bluetooth is not enabled.
- success: Success callback function, invoked when Bluetooth is enabled.
- failure: Error callback function, invoked when Bluetooth is NOT enabled.
bluetoothState.isEnabled(
function() {
console.log("Bluetooth is enabled");
},
function() {
console.log("Bluetooth is *not* enabled");
}
);
Show the Bluetooth settings on the device.
bluetoothState.showBluetoothSettings(success, failure);
Function showBluetoothSettings
opens the Bluetooth settings on the operating systems.
- success: Success callback function [optional]
- failure: Error callback function, invoked when error occurs. [optional]
bluetoothState.showBluetoothSettings();
Enable Bluetooth on the device.
bluetoothState.enable(success, failure);
Function enable
prompts the user to enable Bluetooth.
If enable
is called when Bluetooth is already enabled, the user will not prompted and the success callback will be invoked.
- success: Success callback function, invoked if the user enabled Bluetooth.
- failure: Error callback function, invoked if the user does not enabled Bluetooth.
bluetoothState.enable(
function() {
console.log("Bluetooth is enabled");
},
function() {
console.log("The user did *not* enable Bluetooth");
}
);
The plugin is a semplified version of Don Coleman's BluetoothSerial Plugin
The original BluetoothSerial Plugin is licensed under the Apache License, Version 2.0.