This API is available on Firefox OS for internal applications 仅。
BluetoothAdapter
接口在
Web Bluetooth API
is used to handle all the operations requested by Bluetooth networks. A Bluetooth adapter is the physical interface which is used to interact with local Bluetooth device.
[CheckPermissions="bluetooth"]
interface BluetoothAdapter: EventTarget
{
[AvailableIn=CertifiedApps] readonly attribute DOMString address;
[AvailableIn=CertifiedApps] readonly attribute BluetoothPairingListener pairingReqs;
readonly attribute BluetoothAdapterState state;
readonly attribute DOMString name;
readonly attribute boolean discoverable;
readonly attribute boolean discovering;
readonly attribute BluetoothGattServer? gattServer;
attribute EventHandler onattributechanged;
attribute EventHandler ondevicepaired;
attribute EventHandler ondeviceunpaired;
attribute EventHandler onpairingaborted;
[NewObject, AvailableIn=CertifiedApps] Promise<void> enable();
[NewObject, AvailableIn=CertifiedApps] Promise<void> disable();
[NewObject, AvailableIn=CertifiedApps] Promise<void> setName(DOMString aName);
[NewObject] Promise<void> setDiscoverable(boolean aDiscoverable);
[NewObject] Promise<BluetoothDiscoveryHandle> startDiscovery();
[NewObject] Promise<void> stopDiscovery();
[NewObject] Promise<void> pair(DOMString aAddress);
[NewObject] Promise<void> unpair(DOMString aAddress);
sequence<BluetoothDevice> getPairedDevices();
// BLE methods
[NewObject] Promise<BluetoothDiscoveryHandle> startLeScan(sequence<DOMString> aServiceUuids);
[NewObject] Promise<void> stopLeScan(BluetoothDiscoveryHandle aDiscoveryHandle);
};
BluetoothAdapter.address
只读
A string representing the address of the device's adapter.
BluetoothAdapter.discoverable
只读
true
) 或不 (
false
) by other Bluetooth devices.
BluetoothAdapter.discovering
只读
true
) 或不 (
false
) surrounding Bluetooth devices.
BluetoothAdapter.gattServer
只读
BluetoothGattServer
to use to conduct GATT server operations on the local bluetooth adapter. Will return
null
if the adapter is not enabled.
BluetoothAdapter.name
只读
A string indicating the human readable name of the device's adapter.
BluetoothAdapter.pairingReqs
只读
BluetoothPairingListener
object containing the event handlers needed to response to different pairing types operations.
BluetoothAdapter.state
只读
Returns the state of the local bluetooth adapter.
BluetoothAdapter.onattributechanged
attributechanged
event; it is triggered when one of the local bluetooth adapter's properties has changed
BluetoothAdapter.ondevicepaired
devicepaired
event; it is triggered when a remote device gets paired with the local bluetooth adapter.
BluetoothAdapter.ondeviceunpaired
deviceunpaired
event; it is triggered when a remote device gets unpaired from the local bluetooth adapter.
BluetoothAdapter.onpairingaborted
pairingaborted
event; it is triggered when pairing fails due to authentication failure, the remote device being down (bluetooth ACL becomes disconnected), or some kind of internal error.
注意:
由于
BluetoothAdapter
interface inherits from the
EventTarget
interface, all these events can be listened by using the
addEventListener
方法。
BluetoothAdapter.class
只读
A number representing the Class of Device(CoD) field of the device's adapter.
BluetoothAdapter.discoverableTimeout
只读
A number indicating how long (in seconds) the device remains discoverable.
BluetoothAdapter.devices
只读
数组
of
BluetoothDevice
object representing all the Bluetooth devices discovered in the area surrounding the device.
BluetoothAdapter.uuids
只读
数组
of string, each of them representing the
UUID
of a Bluetooth service the device's adapter is able to provide.
BluetoothAdapter.ona2dpstatuschanged
a2dpstatuschanged
event; it is triggered when an
A2DP
connection status changes.
BluetoothAdapter.ondevicefound
devicefound
event; it is triggered when a Bluetooth device is found.
BluetoothAdapter.onhfpstatuschanged
hfpstatuschanged
event; it is triggered when an
HFP
connection status changes.
BluetoothAdapter.onpairedstatuschanged
pairedstatuschanged
event; it is triggered when a pairing process is completed.
BluetoothAdapter.onrequestmediaplaystatus
requestmediaplaystatus
event; it is triggered when a remote Bluetooth device queries the current media play status.
BluetoothAdapter.onscostatuschanged
scostatuschanged
event; it is triggered when a
SCO
connection status changes.
BluetoothAdapter.enable()
Enables the local bluetooth adapter.
BluetoothAdapter.disable()
Disables the local bluetooth adapter.
BluetoothAdapter.getPairedDevices()
Allows retrieving a full list of all devices paired with the device's adapter.
BluetoothAdapter.pair()
Allows to start pairing a remote device with the device's adapter.
BluetoothAdapter.setDiscoverable()
discoverable
特性。
BluetoothAdapter.startDiscovery()
Allows the device's adapter to start seeking for remote devices.
BluetoothAdapter.startLeScan()
Instructs the device's adapter to start seeking for remote LE devices advertising given services.
BluetoothAdapter.setName()
名称
特性。
BluetoothAdapter.stopDiscovery()
Allows the device's adapter to stop seeking for remote devices.
BluetoothAdapter.stopLeScan()
Instructs the device's adapter to stop scanning for remote LE devices.
BluetoothAdapter.unpair()
Allows to unpair a remote device from the device's adapter.
BluetoothAdapter.answerWaitingCall()
BluetoothAdapter.confirmReceivingFile()
Allows to confirm reception of a file from a remote device.
BluetoothAdapter.connect()
Allows to connect the device to a remote device using a given Bluetooth profile.
BluetoothAdapter.connectSco()
Allows the device to enable the SCO connection to broadcast/listen audio to/from the remote devices it is connected to.
BluetoothAdapter.disconnect()
Allows to disconnect the device from a remote device for one or all Bluetooth profiles.
BluetoothAdapter.disconnectSco()
Allows the device to disable the SCO connection with the remote devices it is connected to.
BluetoothAdapter.getConnectedDevices()
Allows retrieving a full list of all devices connected to the device's adapter.
BluetoothAdapter.ignoreWaitingCall()
BluetoothAdapter.isConnected()
Allows to know if the given Bluetooth service is connected or not.
BluetoothAdapter.isScoConnected()
Allows to know if the device is connected through a SCO connection with the remote devices it is connected to.
BluetoothAdapter.sendFile()
Allows to start sending a file to a given remote device.
BluetoothAdapter.sendMediaMetaData()
BluetoothAdapter.sendMediaPlayStatus()
BluetoothAdapter.setDiscoverableTimeout()
discoverableTimeout
特性。
BluetoothAdapter.setPairingConfirmation()
Allows to accept the pairing confirmation to pair the device's adapter with a remote device.
BluetoothAdapter.setPasskey()
Allows to define a pass key to pair the device's adapter with a remote device.
BluetoothAdapter.setPinCode()
Allows to define a pin code to pair the device's adapter with a remote device.
BluetoothAdapter.stopSendingFile()
Allows to stop sending a file to a given remote device.
BluetoothAdapter.toggleCalls()
| 规范 | 状态 | 注释 |
|---|---|---|
|
Web Bluetooth
The definition of 'BluetoothAdapter' in that specification. |
草案 | Rough draft; not part of any official specification yet. It should be discussed as part of the W3C's System Applications Working Group . |
Firefox OS 2.1 adds Bluetooth 'v2' support:
pairingReqs
,
state
,
onadapterremoved, gattServer
,
onattributechange
,
ondevicepaired
,
ondeviceunpaired
,
onpairingaborted, enable(), disable(), startLeScan(), stopLeScan()
Firefox 1.0.1 Bluetooth initial support:
address
,
discoverable, discovering
,
名称
,
class
,
discoverableTimeout
,
devices
,
uuids, ona2dpstatuschanged
,
ondevicefound
,
onhfpstatuschanged
,
onpairedstatuschanged
,
onrequestmediaplaystatus
,
onscostatuschanged
,
setName()
,
setDiscoverable()
,
startDiscovery()
,
stopdiscovery()
,
pair()
,
unpair()
,
getPairedDevices(), answerWaitingCall(), confirmReceivingFile(), connect(), connectSco(), disconnect(), disconnectSco(), getConnectedDevices(), ignoreWaitingCall(), isConnected(), isScoConnected(), sendFile(), sendMediaMetaData(), sendMediaPlayStatus(), setDiscoverableTimeout(), setPairingConformation(), setPasskey(), setPinCode(), stopSendingFile(), toggleCalls()
Archive
BluetoothAdapter
BluetoothAdapterEvent
BluetoothAttributeEvent
BluetoothClassOfDevice
BluetoothDevice
BluetoothDeviceEvent
BluetoothDiscoveryHandle
BluetoothGatt
BluetoothGattCharacteristic
BluetoothGattCharacteristicEvent
BluetoothGattDescriptor
BluetoothGattServer
BluetoothGattService
BluetoothLeDeviceEvent
BluetoothManager
BluetoothPairingEvent
BluetoothPairingHandle
BluetoothPairingListener