B2G/Bluetooth/WebBluetooth-v2/BluetoothManager

From MozillaWiki
Jump to navigation Jump to search

Overview

The BluetoothManager API allows to access all Bluetooth adapters available on the device. Adapters are the connection interface to connect a Bluetooth device to that device.

Interface

interface BluetoothManager: EventTarget
{
  attribute EventHandler onadapteradded;
  attribute EventHandler onadapterremoved;

  BluetoothAdapter[] getAdapters();
  BluetoothAdapter getDefaultAdapter();
};

Event Handlers

onadapteradded

Summary
A handler to trigger when a bluetooth adapter becomes enabled on the device.
Sample Code
var manager = navigator.mozBluetooth;
manager.onadapteradded = funcRef
Where funcRef is a function to be called when a Bluetooth adapter becomes enabled on the device.

onadapterremoved

Summary
A handler to trigger when a bluetooth adapter becomes disabled on the device.
Sample Code
var manager = navigator.mozBluetooth
manager.onadapterremoved = funcRef
Where funcRef is a function to be called when a Bluetooth adapter becomes disabled on the device.

Methods

getAdapters()

Summary
The getAdapters method is used to retrieve all adapter objects of this device.
Return
The array of all BluetoothAdapter objects.
Sample Code
var adapters = navigator.mozBluetooth.getAdapters();

getDefaultAdapter()

Summary
The getDefaultAdapter method is used to retrieve the default adapter object used to connect the device to third-party Bluetooth devices.
Return
The default BluetoothAdapter object.
Sample Code
var adapter = navigator.mozBluetooth.getDefaultAdapter();

See also

  • BluetoothAdapter