java.lang.Object | |
↳ | android.bluetooth.BluetoothDevice |
Represents a remote Bluetooth device. A BluetoothDevice
lets you
create a connection with the respective device or query information about
it, such as the name, address, class, and bonding state.
This class is really just a thin wrapper for a Bluetooth hardware
address. Objects of this class are immutable. Operations on this class
are performed on the remote Bluetooth hardware address, using the
BluetoothAdapter
that was used to create this BluetoothDevice
.
To get a BluetoothDevice
, use
BluetoothAdapter.getRemoteDevice(String)
to create one representing a device
of a known MAC address (which you can get through device discovery with
BluetoothAdapter
) or get one from the set of bonded devices
returned by BluetoothAdapter.getBondedDevices()
. You can then open a
BluetoothSocket
for communication with the remote device, using
createRfcommSocketToServiceRecord(UUID)
.
Note:
Requires the BLUETOOTH
permission.
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
String | ACTION_ACL_CONNECTED | Broadcast Action: Indicates a low level (ACL) connection has been established with a remote device. | |||||||||
String | ACTION_ACL_DISCONNECTED | Broadcast Action: Indicates a low level (ACL) disconnection from a remote device. | |||||||||
String | ACTION_ACL_DISCONNECT_REQUESTED | Broadcast Action: Indicates that a low level (ACL) disconnection has been requested for a remote device, and it will soon be disconnected. | |||||||||
String | ACTION_BOND_STATE_CHANGED | Broadcast Action: Indicates a change in the bond state of a remote device. | |||||||||
String | ACTION_CLASS_CHANGED | Broadcast Action: Bluetooth class of a remote device has changed. | |||||||||
String | ACTION_FOUND | Broadcast Action: Remote device discovered. | |||||||||
String | ACTION_NAME_CHANGED | Broadcast Action: Indicates the friendly name of a remote device has been retrieved for the first time, or changed since the last retrieval. | |||||||||
int | BOND_BONDED | Indicates the remote device is bonded (paired). | |||||||||
int | BOND_BONDING | Indicates bonding (pairing) is in progress with the remote device. | |||||||||
int | BOND_NONE | Indicates the remote device is not bonded (paired). | |||||||||
Creator<BluetoothDevice> | CREATOR | ||||||||||
int | ERROR | Sentinel error value for this class. | |||||||||
String | EXTRA_BOND_STATE | Used as an int extra field in ACTION_BOND_STATE_CHANGED intents. |
|||||||||
String | EXTRA_CLASS | Used as an Parcelable BluetoothClass extra field in ACTION_FOUND and ACTION_CLASS_CHANGED intents. |
|||||||||
String | EXTRA_DEVICE | Used as a Parcelable BluetoothDevice extra field in every intent
broadcast by this class. |
|||||||||
String | EXTRA_NAME | Used as a String extra field in ACTION_NAME_CHANGED and ACTION_FOUND intents. |
|||||||||
String | EXTRA_PREVIOUS_BOND_STATE | Used as an int extra field in ACTION_BOND_STATE_CHANGED intents. |
|||||||||
String | EXTRA_RSSI | Used as an optional short extra field in ACTION_FOUND intents. |
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From interface
android.os.Parcelable
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Create an RFCOMM
BluetoothSocket ready to start a secure
outgoing connection to this remote device using SDP lookup of uuid. | |||||||||||
Describe the kinds of special objects contained in this Parcelable's
marshalled representation.
| |||||||||||
Compares this instance with the specified object and indicates if they
are equal.
| |||||||||||
Returns the hardware address of this BluetoothDevice.
| |||||||||||
Get the Bluetooth class of the remote device.
| |||||||||||
Get the bond state of the remote device.
| |||||||||||
Get the friendly Bluetooth name of the remote device.
| |||||||||||
Returns an integer hash code for this object.
| |||||||||||
Returns a string representation of this BluetoothDevice.
| |||||||||||
Flatten this object in to a Parcel.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class java.lang.Object
| |||||||||||
From interface android.os.Parcelable
|
Broadcast Action: Indicates a low level (ACL) connection has been established with a remote device.
Always contains the extra field EXTRA_DEVICE
.
ACL connections are managed automatically by the Android Bluetooth stack.
Requires BLUETOOTH
to receive.
Broadcast Action: Indicates a low level (ACL) disconnection from a remote device.
Always contains the extra field EXTRA_DEVICE
.
ACL connections are managed automatically by the Android Bluetooth stack.
Requires BLUETOOTH
to receive.
Broadcast Action: Indicates that a low level (ACL) disconnection has been requested for a remote device, and it will soon be disconnected.
This is useful for graceful disconnection. Applications should use this intent as a hint to immediately terminate higher level connections (RFCOMM, L2CAP, or profile connections) to the remote device.
Always contains the extra field EXTRA_DEVICE
.
Requires BLUETOOTH
to receive.
Broadcast Action: Indicates a change in the bond state of a remote device. For example, if a device is bonded (paired).
Always contains the extra fields EXTRA_DEVICE
, EXTRA_BOND_STATE
and EXTRA_PREVIOUS_BOND_STATE
.
Requires BLUETOOTH
to receive.
Broadcast Action: Bluetooth class of a remote device has changed.
Always contains the extra fields EXTRA_DEVICE
and EXTRA_CLASS
.
Requires BLUETOOTH
to receive.
Broadcast Action: Remote device discovered.
Sent when a remote device is found during discovery.
Always contains the extra fields EXTRA_DEVICE
and EXTRA_CLASS
. Can contain the extra fields EXTRA_NAME
and/or
EXTRA_RSSI
if they are available.
Requires BLUETOOTH
to receive.
Broadcast Action: Indicates the friendly name of a remote device has been retrieved for the first time, or changed since the last retrieval.
Always contains the extra fields EXTRA_DEVICE
and EXTRA_NAME
.
Requires BLUETOOTH
to receive.
Indicates the remote device is bonded (paired).
A shared link keys exists locally for the remote device, so communication can be authenticated and encrypted.
Being bonded (paired) with a remote device does not necessarily mean the device is currently connected. It just means that the pending procedure was completed at some earlier time, and the link key is still stored locally, ready to use on the next connection.
Indicates bonding (pairing) is in progress with the remote device.
Indicates the remote device is not bonded (paired).
There is no shared link key with the remote device, so communication (if it is allowed at all) will be unauthenticated and unencrypted.
Sentinel error value for this class. Guaranteed to not equal any other integer constant in this class. Provided as a convenience for functions that require a sentinel error value, for example:
Intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE,
BluetoothDevice.ERROR)
Used as an int extra field in ACTION_BOND_STATE_CHANGED
intents.
Contains the bond state of the remote device.
Possible values are:
BOND_NONE
,
BOND_BONDING
,
BOND_BONDED
.
Used as an Parcelable BluetoothClass
extra field in ACTION_FOUND
and ACTION_CLASS_CHANGED
intents.
Used as a Parcelable BluetoothDevice
extra field in every intent
broadcast by this class. It contains the BluetoothDevice
that
the intent applies to.
Used as a String extra field in ACTION_NAME_CHANGED
and ACTION_FOUND
intents. It contains the friendly Bluetooth name.
Used as an int extra field in ACTION_BOND_STATE_CHANGED
intents.
Contains the previous bond state of the remote device.
Possible values are:
BOND_NONE
,
BOND_BONDING
,
BOND_BONDED
.
Used as an optional short extra field in ACTION_FOUND
intents.
Contains the RSSI value of the remote device as reported by the
Bluetooth hardware.
Create an RFCOMM BluetoothSocket
ready to start a secure
outgoing connection to this remote device using SDP lookup of uuid.
This is designed to be used with listenUsingRfcommWithServiceRecord(String, UUID)
for peer-peer
Bluetooth applications.
Use connect()
to initiate the outgoing
connection. This will also perform an SDP lookup of the given uuid to
determine which channel to connect to.
The remote device will be authenticated and communication on this socket will be encrypted.
Hint: If you are connecting to a Bluetooth serial board then try using the well-known SPP UUID 00001101-0000-1000-8000-00805F9B34FB. However if you are connecting to an Android peer then please generate your own unique UUID.
Requires BLUETOOTH
uuid | service record uuid to lookup RFCOMM channel |
---|
IOException | on error, for example Bluetooth not available, or insufficient permissions |
---|
Describe the kinds of special objects contained in this Parcelable's marshalled representation.
Compares this instance with the specified object and indicates if they
are equal. In order to be equal, o
must represent the same object
as this instance using a class-specific comparison. The general contract
is that this comparison should be reflexive, symmetric, and transitive.
Also, no object reference other than null is equal to null.
The default implementation returns true
only if this ==
o
. See Writing a correct equals
method
if you intend implementing your own equals
method.
The general contract for the equals
and hashCode()
methods is that if equals
returns true
for
any two objects, then hashCode()
must return the same value for
these objects. This means that subclasses of Object
usually
override either both methods or neither of them.
o | the object to compare this instance with. |
---|
true
if the specified object is equal to this Object
; false
otherwise.Returns the hardware address of this BluetoothDevice.
For example, "00:11:22:AA:BB:CC".
Get the Bluetooth class of the remote device.
Requires BLUETOOTH
.
Get the bond state of the remote device.
Possible values for the bond state are:
BOND_NONE
,
BOND_BONDING
,
BOND_BONDED
.
Requires BLUETOOTH
.
Get the friendly Bluetooth name of the remote device.
The local adapter will automatically retrieve remote names when performing a device scan, and will cache them. This method just returns the name for this device from the cache.
Requires BLUETOOTH
Returns an integer hash code for this object. By contract, any two
objects for which equals(Object)
returns true
must return
the same hash code value. This means that subclasses of Object
usually override both methods or neither method.
Note that hash values must not change over time unless information used in equals comparisons also changes.
See Writing a correct hashCode
method
if you intend implementing your own hashCode
method.
Returns a string representation of this BluetoothDevice.
Currently this is the Bluetooth hardware address, for example
"00:11:22:AA:BB:CC". However, you should always use getAddress()
if you explicitly require the Bluetooth hardware address in case the
toString()
representation changes in the future.
Flatten this object in to a Parcel.
out | The Parcel in which the object should be written. |
---|---|
flags | Additional flags about how the object should be written.
May be 0 or PARCELABLE_WRITE_RETURN_VALUE .
|