chrome.bluetooth
- Description
Use the
chrome.bluetooth
API to connect to a Bluetooth device. All functions report failures via chrome.runtime.lastError.
Summary
- Types
- Methods
chrome.bluetooth.getAdapterState(callback: function)
chrome.bluetooth.getDevice(deviceAddress: string, callback: function)
chrome.bluetooth.getDevices(filter?: BluetoothFilter, callback: function)
chrome.bluetooth.startDiscovery(callback: function)
chrome.bluetooth.stopDiscovery(callback: function)
- Events
Types
AdapterState
Properties
- addressstring
The address of the adapter, in the format 'XX:XX:XX:XX:XX:XX'.
- availableboolean
Indicates whether or not the adapter is available (i.e. enabled).
- discoveringboolean
Indicates whether or not the adapter is currently discovering.
- namestring
The human-readable name of the adapter.
- poweredboolean
Indicates whether or not the adapter has power.
BluetoothFilter
Properties
- filterTypeFilterType optional
Type of filter to apply to the device list. Default is all.
- limitnumber optional
Maximum number of bluetoth devices to return. Default is 0 (no limit) if unspecified.
Device
Properties
- addressstring
The address of the device, in the format 'XX:XX:XX:XX:XX:XX'.
- batteryPercentagenumber optional
The remaining battery of the device. TODO(https://crbug.com/973237): This field is only used by Chrome OS and it is different from others because it is not filled by the platform. In the future, when there is a unified Mojo service, this field will be moved to BluetoothDeviceInfo.
- connectableboolean optional
Indicates whether the device is connectable.
- connectedboolean optional
Indicates whether the device is currently connected to the system.
- connectingboolean optional
Indicates whether the device is currently connecting to the system.
- deviceClassnumber optional
The class of the device, a bit-field defined by http://www.bluetooth.org/en-us/specification/assigned-numbers/baseband.
- deviceIdnumber optional
- inquiryRssinumber optional
The received signal strength, in dBm. This field is avaliable and valid only during discovery. Outside of discovery it's value is not specified.
- inquiryTxPowernumber optional
The transmitted power level. This field is avaliable only for LE devices that include this field in AD. It is avaliable and valid only during discovery.
- namestring optional
The human-readable name of the device.
- pairedboolean optional
Indicates whether or not the device is paired with the system.
- productIdnumber optional
- transportTransport optional
The transport type of the bluetooth device.
- typeDeviceType optional
The type of the device, if recognized by Chrome. This is obtained from the |deviceClass| field and only represents a small fraction of the possible device types. When in doubt you should use the |deviceClass| field directly.
- uuidsstring[] optional
UUIDs of protocols, profiles and services advertised by the device. For classic Bluetooth devices, this list is obtained from EIR data and SDP tables. For Low Energy devices, this list is obtained from AD and GATT primary services. For dual mode devices this may be obtained from both.
- vendorIdnumber optional
- vendorIdSourceVendorIdSource optional
The Device ID record of the device, where available.
DeviceType
Common device types recognized by Chrome.
Enum
"computer"
, "phone"
, "modem"
, "audio"
, "carAudio"
, "video"
, "peripheral"
, "joystick"
, "gamepad"
, "keyboard"
, "mouse"
, "tablet"
, or "keyboardMouseCombo"
FilterType
Types for filtering bluetooth devices.
Enum
"all"
, or "known"
Transport
Transport type of the bluetooth device.
Enum
"invalid"
, "classic"
, "le"
, or "dual"
VendorIdSource
Allocation authorities for Vendor IDs.
Enum
"bluetooth"
, or "usb"
Methods
getAdapterState
chrome.bluetooth.getAdapterState(callback: function)
Get information about the Bluetooth adapter.
Parameters
- callbackfunction
Called with an AdapterState object describing the adapter state.
The callback parameter should be a function that looks like this:
(adapterInfo: AdapterState) => {...}
- adapterInfo
Object containing the adapter information.
getDevice
chrome.bluetooth.getDevice(deviceAddress: string, callback: function)
Get information about a Bluetooth device known to the system.
getDevices
chrome.bluetooth.getDevices(filter?: BluetoothFilter, callback: function)
Get a list of Bluetooth devices known to the system, including paired and recently discovered devices.
Parameters
- filterBluetoothFilter optional
Some criteria to filter the list of returned bluetooth devices. If the filter is not set or set to
{}
, returned device list will contain all bluetooth devices. Right now this is only supported in ChromeOS, for other platforms, a full list is returned. - callbackfunction
startDiscovery
chrome.bluetooth.startDiscovery(callback: function)
Start discovery. Newly discovered devices will be returned via the onDeviceAdded event. Previously discovered devices already known to the adapter must be obtained using getDevices and will only be updated using the |onDeviceChanged| event if information about them changes.
Discovery will fail to start if this application has already called startDiscovery. Discovery can be resource intensive: stopDiscovery should be called as soon as possible.
Parameters
- callbackfunction
Called to indicate success or failure.
The callback parameter should be a function that looks like this:
() => {...}
stopDiscovery
chrome.bluetooth.stopDiscovery(callback: function)
Stop discovery.
Parameters
- callbackfunction
Called to indicate success or failure.
The callback parameter should be a function that looks like this:
() => {...}
Events
onAdapterStateChanged
chrome.bluetooth.onAdapterStateChanged.addListener(listener: function)
Fired when the state of the Bluetooth adapter changes.
Event
- listenerfunction
The listener parameter should be a function that looks like this:
(state: AdapterState) => {...}
- state
The new state of the adapter.
onDeviceAdded
chrome.bluetooth.onDeviceAdded.addListener(listener: function)
Fired when information about a new Bluetooth device is available.
onDeviceChanged
chrome.bluetooth.onDeviceChanged.addListener(listener: function)
Fired when information about a known Bluetooth device has changed.
onDeviceRemoved
chrome.bluetooth.onDeviceRemoved.addListener(listener: function)
Fired when a Bluetooth device that was previously discovered has been out of range for long enough to be considered unavailable again, and when a paired device is removed.