public final class BluetoothDevice extends Object implements Parcelable
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 android.Manifest.permission#BLUETOOTH
permission.
For more information about using Bluetooth, read the Bluetooth developer guide.
BluetoothAdapter
BluetoothSocket
Parcelable.ClassLoaderCreator<T>, Parcelable.Creator<T>
Modifier and Type | Field and Description |
---|---|
static int |
ACCESS_ALLOWED
|
static int |
ACCESS_REJECTED
|
static int |
ACCESS_UNKNOWN
|
static String |
ACTION_ACL_CONNECTED
Broadcast Action: Indicates a low level (ACL) connection has been
established with a remote device.
|
static 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.
|
static String |
ACTION_ACL_DISCONNECTED
Broadcast Action: Indicates a low level (ACL) disconnection from a
remote device.
|
static String |
ACTION_ALIAS_CHANGED
Broadcast Action: Indicates the alias of a remote device has been
changed.
|
static String |
ACTION_BOND_STATE_CHANGED
Broadcast Action: Indicates a change in the bond state of a remote
device.
|
static String |
ACTION_CLASS_CHANGED
Broadcast Action: Bluetooth class of a remote device has changed.
|
static String |
ACTION_CONNECTION_ACCESS_CANCEL |
static String |
ACTION_CONNECTION_ACCESS_REPLY |
static String |
ACTION_CONNECTION_ACCESS_REQUEST |
static String |
ACTION_DISAPPEARED
Broadcast Action: Remote device disappeared.
|
static String |
ACTION_FOUND
Broadcast Action: Remote device discovered.
|
static String |
ACTION_MAS_INSTANCE |
static 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.
|
static String |
ACTION_NAME_FAILED
Broadcast Action: Indicates a failure to retrieve the name of a remote
device.
|
static String |
ACTION_PAIRING_CANCEL |
static String |
ACTION_PAIRING_REQUEST
Broadcast Action: This intent is used to broadcast PAIRING REQUEST
Requires
android.Manifest.permission#BLUETOOTH_ADMIN to
receive. |
static String |
ACTION_SDP_RECORD |
static String |
ACTION_UUID
Broadcast Action: This intent is used to broadcast the
UUID
wrapped as a ParcelUuid of the remote device after it
has been fetched. |
static int |
BOND_BONDED
Indicates the remote device is bonded (paired).
|
static int |
BOND_BONDING
Indicates bonding (pairing) is in progress with the remote device.
|
static int |
BOND_NONE
Indicates the remote device is not bonded (paired).
|
static int |
BOND_SUCCESS
A bond attempt succeeded
|
static int |
CONNECTION_ACCESS_NO |
static int |
CONNECTION_ACCESS_YES |
static Parcelable.Creator<BluetoothDevice> |
CREATOR |
static int |
DEVICE_TYPE_CLASSIC
Bluetooth device type, Classic - BR/EDR devices
|
static int |
DEVICE_TYPE_DUAL
Bluetooth device type, Dual Mode - BR/EDR/LE
|
static int |
DEVICE_TYPE_LE
Bluetooth device type, Low Energy - LE-only
|
static int |
DEVICE_TYPE_UNKNOWN
Bluetooth device type, Unknown
|
static int |
ERROR
Sentinel error value for this class.
|
static String |
EXTRA_ACCESS_REQUEST_TYPE
Used as an extra field in
ACTION_CONNECTION_ACCESS_REQUEST intent. |
static String |
EXTRA_ALWAYS_ALLOWED
Used as an extra field in
ACTION_CONNECTION_ACCESS_REPLY intents,
Contains boolean to indicate if the allowed response is once-for-all so that
next request will be granted without asking user again. |
static String |
EXTRA_BOND_STATE
Used as an int extra field in
ACTION_BOND_STATE_CHANGED intents. |
static String |
EXTRA_CLASS
|
static String |
EXTRA_CLASS_NAME
Used as an extra field in
ACTION_CONNECTION_ACCESS_REQUEST intents,
Contains class name to return reply intent to. |
static String |
EXTRA_CONNECTION_ACCESS_RESULT
Used as an extra field in
ACTION_CONNECTION_ACCESS_REPLY intent. |
static String |
EXTRA_DEVICE
Used as a Parcelable
BluetoothDevice extra field in every intent
broadcast by this class. |
static String |
EXTRA_MAS_INSTANCE |
static String |
EXTRA_NAME
Used as a String extra field in
ACTION_NAME_CHANGED and ACTION_FOUND intents. |
static String |
EXTRA_PACKAGE_NAME
Used as an extra field in
ACTION_CONNECTION_ACCESS_REQUEST intents,
Contains package name to return reply intent to. |
static String |
EXTRA_PAIRING_KEY
Used as an int extra field in
ACTION_PAIRING_REQUEST
intents as the value of passkey. |
static String |
EXTRA_PAIRING_VARIANT
Used as an int extra field in
ACTION_PAIRING_REQUEST
intents to indicate pairing method used. |
static String |
EXTRA_PREVIOUS_BOND_STATE
Used as an int extra field in
ACTION_BOND_STATE_CHANGED intents. |
static String |
EXTRA_REASON
Used as an int extra field in
ACTION_PAIRING_REQUEST
intents for unbond reason. |
static String |
EXTRA_RSSI
Used as an optional short extra field in
ACTION_FOUND intents. |
static String |
EXTRA_SDP_RECORD |
static String |
EXTRA_SDP_SEARCH_STATUS |
static String |
EXTRA_UUID
Used as an extra field in
ACTION_UUID intents,
Contains the ParcelUuid s of the remote device which
is a parcelable version of UUID . |
static int |
PAIRING_VARIANT_CONSENT
The user will be prompted to accept or deny the incoming pairing request
|
static int |
PAIRING_VARIANT_DISPLAY_PASSKEY
The user will be prompted to enter the passkey displayed on remote device
This is used for Bluetooth 2.1 pairing.
|
static int |
PAIRING_VARIANT_DISPLAY_PIN
The user will be prompted to enter the PIN displayed on remote device.
|
static int |
PAIRING_VARIANT_OOB_CONSENT
The user will be prompted to accept or deny the OOB pairing request
|
static int |
PAIRING_VARIANT_PASSKEY
The user will be prompted to enter a passkey
|
static int |
PAIRING_VARIANT_PASSKEY_CONFIRMATION
The user will be prompted to confirm the passkey displayed on the screen or
an app will confirm the passkey for the user.
|
static int |
PAIRING_VARIANT_PIN
The user will be prompted to enter a pin or
an app will enter a pin for user.
|
static int |
PAIRING_VARIANT_PIN_16_DIGITS
The user will be prompted to enter a 16 digit pin or
an app will enter a 16 digit pin for user.
|
static int |
REQUEST_TYPE_MESSAGE_ACCESS |
static int |
REQUEST_TYPE_PHONEBOOK_ACCESS |
static int |
REQUEST_TYPE_PROFILE_CONNECTION |
static int |
REQUEST_TYPE_SIM_ACCESS |
static int |
TRANSPORT_AUTO
No preferrence of physical transport for GATT connections to remote dual-mode devices
|
static int |
TRANSPORT_BREDR
Prefer BR/EDR transport for GATT connections to remote dual-mode devices
|
static int |
TRANSPORT_LE
Prefer LE transport for GATT connections to remote dual-mode devices
|
static int |
UNBOND_REASON_AUTH_CANCELED
A bond attempt failed because we canceled the bonding process
|
static int |
UNBOND_REASON_AUTH_FAILED
A bond attempt failed because pins did not match, or remote device did
not respond to pin request in time
|
static int |
UNBOND_REASON_AUTH_REJECTED
A bond attempt failed because the other side explicitly rejected
bonding
|
static int |
UNBOND_REASON_AUTH_TIMEOUT
A bond attempt failed because of authentication timeout
|
static int |
UNBOND_REASON_DISCOVERY_IN_PROGRESS
A bond attempt failed because a discovery is in progress
|
static int |
UNBOND_REASON_REMOTE_AUTH_CANCELED
A bond attempt failed because we received an Authentication Cancel
by remote end
|
static int |
UNBOND_REASON_REMOTE_DEVICE_DOWN
A bond attempt failed because we could not contact the remote device
|
static int |
UNBOND_REASON_REMOVED
An existing bond was explicitly revoked
|
static int |
UNBOND_REASON_REPEATED_ATTEMPTS
A bond attempt failed because of repeated attempts
|
CONTENTS_FILE_DESCRIPTOR, PARCELABLE_ELIDE_DUPLICATES, PARCELABLE_WRITE_RETURN_VALUE
Modifier and Type | Method and Description |
---|---|
boolean |
cancelBondProcess()
Cancel an in-progress bonding request started with
createBond() . |
boolean |
cancelPairingUserInput() |
BluetoothGatt |
connectGatt(Context context,
boolean autoConnect,
BluetoothGattCallback callback)
Connect to GATT Server hosted by this device.
|
BluetoothGatt |
connectGatt(Context context,
boolean autoConnect,
BluetoothGattCallback callback,
int transport)
Connect to GATT Server hosted by this device.
|
static byte[] |
convertPinToBytes(String pin)
Check that a pin is valid and convert to byte array.
|
boolean |
createBond()
Start the bonding (pairing) process with the remote device.
|
boolean |
createBond(int transport)
Start the bonding (pairing) process with the remote device using the
specified transport.
|
boolean |
createBondOutOfBand(int transport,
OobData oobData)
Start the bonding (pairing) process with the remote device using the
Out Of Band mechanism.
|
BluetoothSocket |
createInsecureRfcommSocket(int port)
Construct an insecure RFCOMM socket ready to start an outgoing
connection.
|
BluetoothSocket |
createInsecureRfcommSocketToServiceRecord(UUID uuid)
Create an RFCOMM
BluetoothSocket socket ready to start an insecure
outgoing connection to this remote device using SDP lookup of uuid. |
BluetoothSocket |
createL2capSocket(int channel)
Create an L2cap
BluetoothSocket ready to start a secure
outgoing connection to this remote device on given channel. |
BluetoothSocket |
createRfcommSocket(int channel)
Create an RFCOMM
BluetoothSocket ready to start a secure
outgoing connection to this remote device on given channel. |
BluetoothSocket |
createRfcommSocketToServiceRecord(UUID uuid)
Create an RFCOMM
BluetoothSocket ready to start a secure
outgoing connection to this remote device using SDP lookup of uuid. |
BluetoothSocket |
createScoSocket()
Construct a SCO socket ready to start an outgoing connection.
|
int |
describeContents()
Describe the kinds of special objects contained in this Parcelable
instance's marshaled representation.
|
boolean |
equals(Object o)
Indicates whether some other object is "equal to" this one.
|
boolean |
fetchUuidsWithSdp()
Perform a service discovery on the remote device to get the UUIDs supported.
|
String |
getAddress()
Returns the hardware address of this BluetoothDevice.
|
String |
getAlias()
Get the Bluetooth alias of the remote device.
|
String |
getAliasName()
Get the Bluetooth alias of the remote device.
|
BluetoothClass |
getBluetoothClass()
Get the Bluetooth class of the remote device.
|
int |
getBondState()
Get the bond state of the remote device.
|
int |
getMessageAccessPermission()
Requires
android.Manifest.permission#BLUETOOTH . |
String |
getName()
Get the friendly Bluetooth name of the remote device.
|
int |
getPhonebookAccessPermission()
Requires
android.Manifest.permission#BLUETOOTH . |
int |
getSimAccessPermission()
Requires
android.Manifest.permission#BLUETOOTH . |
int |
getType()
Get the Bluetooth device type of the remote device.
|
ParcelUuid[] |
getUuids()
Returns the supported features (UUIDs) of the remote device.
|
int |
hashCode()
Returns a hash code value for the object.
|
boolean |
isBluetoothDock() |
boolean |
isConnected()
Returns whether there is an open connection to this device.
|
boolean |
isEncrypted()
Returns whether there is an open connection to this device
that has been encrypted.
|
boolean |
removeBond()
Remove bond (pairing) with the remote device.
|
boolean |
sdpSearch(ParcelUuid uuid) |
boolean |
setAlias(String alias)
Set the Bluetooth alias of the remote device.
|
boolean |
setDeviceOutOfBandData(byte[] hash,
byte[] randomizer)
Set the Out Of Band data for a remote device to be used later
in the pairing mechanism.
|
boolean |
setMessageAccessPermission(int value)
Sets whether the message access is allowed to this device.
|
boolean |
setPairingConfirmation(boolean confirm)
Confirm passkey for
PAIRING_VARIANT_PASSKEY_CONFIRMATION pairing. |
boolean |
setPasskey(int passkey) |
boolean |
setPhonebookAccessPermission(int value)
Sets whether the phonebook access is allowed to this device.
|
boolean |
setPin(byte[] pin)
Set the pin during pairing when the pairing method is
PAIRING_VARIANT_PIN
Requires android.Manifest.permission#BLUETOOTH_ADMIN . |
boolean |
setRemoteOutOfBandData() |
boolean |
setSimAccessPermission(int value)
Sets whether the Sim access is allowed to this device.
|
String |
toString()
Returns a string representation of this BluetoothDevice.
|
void |
writeToParcel(Parcel out,
int flags)
Flatten this object in to a Parcel.
|
public static final int ERROR
Intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE,
BluetoothDevice.ERROR)
public static final String ACTION_FOUND
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 android.Manifest.permission#BLUETOOTH
and
android.Manifest.permission#ACCESS_COARSE_LOCATION
to receive.
public static final String ACTION_DISAPPEARED
Sent when a remote device that was found in the last discovery is not found in the current discovery.
Always contains the extra field EXTRA_DEVICE
.
Requires android.Manifest.permission#BLUETOOTH
to receive.
public static final String ACTION_CLASS_CHANGED
Always contains the extra fields EXTRA_DEVICE
and EXTRA_CLASS
.
Requires android.Manifest.permission#BLUETOOTH
to receive.
BluetoothClass
public static final String ACTION_ACL_CONNECTED
Always contains the extra field EXTRA_DEVICE
.
ACL connections are managed automatically by the Android Bluetooth stack.
Requires android.Manifest.permission#BLUETOOTH
to receive.
public static final String ACTION_ACL_DISCONNECT_REQUESTED
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 android.Manifest.permission#BLUETOOTH
to receive.
public static final String ACTION_ACL_DISCONNECTED
Always contains the extra field EXTRA_DEVICE
.
ACL connections are managed automatically by the Android Bluetooth stack.
Requires android.Manifest.permission#BLUETOOTH
to receive.
public static final String ACTION_NAME_CHANGED
Always contains the extra fields EXTRA_DEVICE
and EXTRA_NAME
.
Requires android.Manifest.permission#BLUETOOTH
to receive.
public static final String ACTION_ALIAS_CHANGED
Always contains the extra field EXTRA_DEVICE
.
Requires android.Manifest.permission#BLUETOOTH
to receive.
public static final String ACTION_BOND_STATE_CHANGED
Always contains the extra fields EXTRA_DEVICE
, EXTRA_BOND_STATE
and EXTRA_PREVIOUS_BOND_STATE
.
Requires android.Manifest.permission#BLUETOOTH
to receive.
public static final String EXTRA_DEVICE
BluetoothDevice
extra field in every intent
broadcast by this class. It contains the BluetoothDevice
that
the intent applies to.public static final String EXTRA_NAME
ACTION_NAME_CHANGED
and ACTION_FOUND
intents. It contains the friendly Bluetooth name.public static final String EXTRA_RSSI
ACTION_FOUND
intents.
Contains the RSSI value of the remote device as reported by the
Bluetooth hardware.public static final String EXTRA_CLASS
public static final String EXTRA_BOND_STATE
ACTION_BOND_STATE_CHANGED
intents.
Contains the bond state of the remote device.
Possible values are:
BOND_NONE
,
BOND_BONDING
,
BOND_BONDED
.
public static final String EXTRA_PREVIOUS_BOND_STATE
ACTION_BOND_STATE_CHANGED
intents.
Contains the previous bond state of the remote device.
Possible values are:
BOND_NONE
,
BOND_BONDING
,
BOND_BONDED
.
public static final int BOND_NONE
There is no shared link key with the remote device, so communication (if it is allowed at all) will be unauthenticated and unencrypted.
public static final int BOND_BONDING
public static final int BOND_BONDED
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.
public static final String EXTRA_REASON
ACTION_PAIRING_REQUEST
intents for unbond reason.public static final String EXTRA_PAIRING_VARIANT
ACTION_PAIRING_REQUEST
intents to indicate pairing method used. Possible values are:
PAIRING_VARIANT_PIN
,
PAIRING_VARIANT_PASSKEY_CONFIRMATION
,public static final String EXTRA_PAIRING_KEY
ACTION_PAIRING_REQUEST
intents as the value of passkey.public static final int DEVICE_TYPE_UNKNOWN
public static final int DEVICE_TYPE_CLASSIC
public static final int DEVICE_TYPE_LE
public static final int DEVICE_TYPE_DUAL
public static final String ACTION_SDP_RECORD
public static final String ACTION_UUID
UUID
wrapped as a ParcelUuid
of the remote device after it
has been fetched. This intent is sent only when the UUIDs of the remote
device are requested to be fetched using Service Discovery Protocol
Always contains the extra field EXTRA_DEVICE
Always contains the extra field EXTRA_UUID
Requires android.Manifest.permission#BLUETOOTH
to receive.
public static final String ACTION_MAS_INSTANCE
public static final String ACTION_NAME_FAILED
Always contains the extra field EXTRA_DEVICE
.
Requires android.Manifest.permission#BLUETOOTH
to receive.
public static final String ACTION_PAIRING_REQUEST
Requires android.Manifest.permission#BLUETOOTH_ADMIN
to
receive.
public static final String ACTION_PAIRING_CANCEL
public static final String ACTION_CONNECTION_ACCESS_REQUEST
public static final String ACTION_CONNECTION_ACCESS_REPLY
public static final String ACTION_CONNECTION_ACCESS_CANCEL
public static final String EXTRA_ACCESS_REQUEST_TYPE
ACTION_CONNECTION_ACCESS_REQUEST
intent.public static final int REQUEST_TYPE_PROFILE_CONNECTION
public static final int REQUEST_TYPE_PHONEBOOK_ACCESS
public static final int REQUEST_TYPE_MESSAGE_ACCESS
public static final int REQUEST_TYPE_SIM_ACCESS
public static final String EXTRA_PACKAGE_NAME
ACTION_CONNECTION_ACCESS_REQUEST
intents,
Contains package name to return reply intent to.public static final String EXTRA_CLASS_NAME
ACTION_CONNECTION_ACCESS_REQUEST
intents,
Contains class name to return reply intent to.public static final String EXTRA_CONNECTION_ACCESS_RESULT
ACTION_CONNECTION_ACCESS_REPLY
intent.public static final int CONNECTION_ACCESS_YES
public static final int CONNECTION_ACCESS_NO
public static final String EXTRA_ALWAYS_ALLOWED
ACTION_CONNECTION_ACCESS_REPLY
intents,
Contains boolean to indicate if the allowed response is once-for-all so that
next request will be granted without asking user again.public static final int BOND_SUCCESS
public static final int UNBOND_REASON_AUTH_FAILED
public static final int UNBOND_REASON_AUTH_REJECTED
public static final int UNBOND_REASON_AUTH_CANCELED
public static final int UNBOND_REASON_REMOTE_DEVICE_DOWN
public static final int UNBOND_REASON_DISCOVERY_IN_PROGRESS
public static final int UNBOND_REASON_AUTH_TIMEOUT
public static final int UNBOND_REASON_REPEATED_ATTEMPTS
public static final int UNBOND_REASON_REMOTE_AUTH_CANCELED
public static final int UNBOND_REASON_REMOVED
public static final int PAIRING_VARIANT_PIN
public static final int PAIRING_VARIANT_PASSKEY
public static final int PAIRING_VARIANT_PASSKEY_CONFIRMATION
public static final int PAIRING_VARIANT_CONSENT
public static final int PAIRING_VARIANT_DISPLAY_PASSKEY
public static final int PAIRING_VARIANT_DISPLAY_PIN
public static final int PAIRING_VARIANT_OOB_CONSENT
public static final int PAIRING_VARIANT_PIN_16_DIGITS
public static final String EXTRA_UUID
ACTION_UUID
intents,
Contains the ParcelUuid
s of the remote device which
is a parcelable version of UUID
.public static final String EXTRA_SDP_RECORD
public static final String EXTRA_SDP_SEARCH_STATUS
public static final int ACCESS_UNKNOWN
getPhonebookAccessPermission()
, setPhonebookAccessPermission(int)
,
getMessageAccessPermission()
and setMessageAccessPermission(int)
.public static final int ACCESS_ALLOWED
getPhonebookAccessPermission()
, setPhonebookAccessPermission(int)
,
getMessageAccessPermission()
and setMessageAccessPermission(int)
.public static final int ACCESS_REJECTED
getPhonebookAccessPermission()
, setPhonebookAccessPermission(int)
,
getMessageAccessPermission()
and setMessageAccessPermission(int)
.public static final int TRANSPORT_AUTO
public static final int TRANSPORT_BREDR
public static final int TRANSPORT_LE
public static final String EXTRA_MAS_INSTANCE
public static final Parcelable.Creator<BluetoothDevice> CREATOR
public boolean equals(Object o)
Object
The equals
method implements an equivalence relation
on non-null object references:
x
, x.equals(x)
should return
true
.
x
and y
, x.equals(y)
should return true
if and only if
y.equals(x)
returns true
.
x
, y
, and z
, if
x.equals(y)
returns true
and
y.equals(z)
returns true
, then
x.equals(z)
should return true
.
x
and y
, multiple invocations of
x.equals(y)
consistently return true
or consistently return false
, provided no
information used in equals
comparisons on the
objects is modified.
x
,
x.equals(null)
should return false
.
The equals
method for class Object
implements
the most discriminating possible equivalence relation on objects;
that is, for any non-null reference values x
and
y
, this method returns true
if and only
if x
and y
refer to the same object
(x == y
has the value true
).
Note that it is generally necessary to override the hashCode
method whenever this method is overridden, so as to maintain the
general contract for the hashCode
method, which states
that equal objects must have equal hash codes.
equals
in class Object
o
- the reference object with which to compare.true
if this object is the same as the obj
argument; false
otherwise.Object.hashCode()
,
HashMap
public int hashCode()
Object
HashMap
.
The general contract of hashCode
is:
hashCode
method
must consistently return the same integer, provided no information
used in equals
comparisons on the object is modified.
This integer need not remain consistent from one execution of an
application to another execution of the same application.
equals(Object)
method, then calling the hashCode
method on each of
the two objects must produce the same integer result.
Object.equals(java.lang.Object)
method, then calling the hashCode
method on each of the
two objects must produce distinct integer results. However, the
programmer should be aware that producing distinct integer results
for unequal objects may improve the performance of hash tables.
As much as is reasonably practical, the hashCode method defined by
class Object
does return distinct integers for distinct
objects. (This is typically implemented by converting the internal
address of the object into an integer, but this implementation
technique is not required by the
JavaTM programming language.)
hashCode
in class Object
Object.equals(java.lang.Object)
,
System.identityHashCode(java.lang.Object)
public String toString()
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.
public int describeContents()
Parcelable
Parcelable.writeToParcel(Parcel, int)
,
the return value of this method must include the
Parcelable.CONTENTS_FILE_DESCRIPTOR
bit.describeContents
in interface Parcelable
Parcelable.CONTENTS_FILE_DESCRIPTOR
public void writeToParcel(Parcel out, int flags)
Parcelable
writeToParcel
in interface Parcelable
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.PARCELABLE_WRITE_RETURN_VALUE
.public String getAddress()
For example, "00:11:22:AA:BB:CC".
public String getName()
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 android.Manifest.permission#BLUETOOTH
public int getType()
Requires android.Manifest.permission#BLUETOOTH
DEVICE_TYPE_CLASSIC
, DEVICE_TYPE_LE
DEVICE_TYPE_DUAL
.
DEVICE_TYPE_UNKNOWN
if it's not availablepublic String getAlias()
Alias is the locally modified name of a remote device.
public boolean setAlias(String alias)
Alias is the locally modified name of a remote device.
This methoid overwrites the alias. The changed alias is saved in the local storage so that the change is preserved over power cycle.
public String getAliasName()
getAlias()
,
getName()
public boolean createBond()
This is an asynchronous call, it will return immediately. Register
for ACTION_BOND_STATE_CHANGED
intents to be notified when
the bonding process completes, and its result.
Android system services will handle the necessary user interactions to confirm and complete the bonding process.
Requires android.Manifest.permission#BLUETOOTH_ADMIN
.
public boolean createBond(int transport)
This is an asynchronous call, it will return immediately. Register
for ACTION_BOND_STATE_CHANGED
intents to be notified when
the bonding process completes, and its result.
Android system services will handle the necessary user interactions to confirm and complete the bonding process.
Requires android.Manifest.permission#BLUETOOTH_ADMIN
.
transport
- The transport to use for the pairing procedure.IllegalArgumentException
- if an invalid transport was specifiedpublic boolean createBondOutOfBand(int transport, OobData oobData)
This is an asynchronous call, it will return immediately. Register
for ACTION_BOND_STATE_CHANGED
intents to be notified when
the bonding process completes, and its result.
Android system services will handle the necessary user interactions to confirm and complete the bonding process.
Requires android.Manifest.permission#BLUETOOTH_ADMIN
.
transport
- - Transport to useoobData
- - Out Of Band datapublic boolean setDeviceOutOfBandData(byte[] hash, byte[] randomizer)
Requires android.Manifest.permission#BLUETOOTH_ADMIN
.
hash
- Simple Secure pairing hashrandomizer
- The random key obtained using OOBpublic boolean cancelBondProcess()
createBond()
.
Requires android.Manifest.permission#BLUETOOTH_ADMIN
.
public boolean removeBond()
Delete the link key associated with the remote device, and immediately terminate connections to that device that require authentication and encryption.
Requires android.Manifest.permission#BLUETOOTH_ADMIN
.
public int getBondState()
Possible values for the bond state are:
BOND_NONE
,
BOND_BONDING
,
BOND_BONDED
.
Requires android.Manifest.permission#BLUETOOTH
.
public boolean isConnected()
Requires android.Manifest.permission#BLUETOOTH
.
public boolean isEncrypted()
Requires android.Manifest.permission#BLUETOOTH
.
public BluetoothClass getBluetoothClass()
Requires android.Manifest.permission#BLUETOOTH
.
public ParcelUuid[] getUuids()
This method does not start a service discovery procedure to retrieve the UUIDs from the remote device. Instead, the local cached copy of the service UUIDs are returned.
Use fetchUuidsWithSdp()
if fresh UUIDs are desired.
Requires android.Manifest.permission#BLUETOOTH
.
public boolean fetchUuidsWithSdp()
This API is asynchronous and ACTION_UUID
intent is sent,
with the UUIDs supported by the remote end. If there is an error
in getting the SDP records or if the process takes a long time,
ACTION_UUID
intent is sent with the UUIDs that is currently
present in the cache. Clients should use the getUuids()
to get UUIDs
if service discovery is not to be performed.
Requires android.Manifest.permission#BLUETOOTH
.
public boolean sdpSearch(ParcelUuid uuid)
public boolean setPin(byte[] pin)
PAIRING_VARIANT_PIN
Requires android.Manifest.permission#BLUETOOTH_ADMIN
.
public boolean setPasskey(int passkey)
public boolean setPairingConfirmation(boolean confirm)
PAIRING_VARIANT_PASSKEY_CONFIRMATION
pairing.
Requires android.Manifest.permission#BLUETOOTH_PRIVILEGED
.
public boolean setRemoteOutOfBandData()
public boolean cancelPairingUserInput()
public boolean isBluetoothDock()
public int getPhonebookAccessPermission()
android.Manifest.permission#BLUETOOTH
.ACCESS_UNKNOWN
, ACCESS_ALLOWED
or ACCESS_REJECTED
.public boolean setPhonebookAccessPermission(int value)
Requires android.Manifest.permission#BLUETOOTH_PRIVILEGED
.
value
- Can be ACCESS_UNKNOWN
, ACCESS_ALLOWED
or
ACCESS_REJECTED
.public int getMessageAccessPermission()
android.Manifest.permission#BLUETOOTH
.ACCESS_UNKNOWN
, ACCESS_ALLOWED
or ACCESS_REJECTED
.public boolean setMessageAccessPermission(int value)
Requires android.Manifest.permission#BLUETOOTH_PRIVILEGED
.
value
- Can be ACCESS_UNKNOWN
, ACCESS_ALLOWED
or
ACCESS_REJECTED
.public int getSimAccessPermission()
android.Manifest.permission#BLUETOOTH
.ACCESS_UNKNOWN
, ACCESS_ALLOWED
or ACCESS_REJECTED
.public boolean setSimAccessPermission(int value)
Requires android.Manifest.permission#BLUETOOTH_PRIVILEGED
.
value
- Can be ACCESS_UNKNOWN
, ACCESS_ALLOWED
or
ACCESS_REJECTED
.public BluetoothSocket createRfcommSocket(int channel) throws IOException
BluetoothSocket
ready to start a secure
outgoing connection to this remote device on given channel.
The remote device will be authenticated and communication on this socket will be encrypted.
Use this socket only if an authenticated socket link is possible. Authentication refers to the authentication of the link key to prevent man-in-the-middle type of attacks. For example, for Bluetooth 2.1 devices, if any of the devices does not have an input and output capability or just has the ability to display a numeric key, a secure socket connection is not possible. In such a case, use {#link createInsecureRfcommSocket}. For more details, refer to the Security Model section 5.2 (vol 3) of Bluetooth Core Specification version 2.1 + EDR.
Use BluetoothSocket.connect()
to initiate the outgoing
connection.
Valid RFCOMM channels are in range 1 to 30.
Requires android.Manifest.permission#BLUETOOTH
channel
- RFCOMM channel to connect toIOException
- on error, for example Bluetooth not available, or
insufficient permissionspublic BluetoothSocket createL2capSocket(int channel) throws IOException
BluetoothSocket
ready to start a secure
outgoing connection to this remote device on given channel.
The remote device will be authenticated and communication on this socket will be encrypted.
Use this socket only if an authenticated socket link is possible. Authentication refers to the authentication of the link key to prevent man-in-the-middle type of attacks. For example, for Bluetooth 2.1 devices, if any of the devices does not have an input and output capability or just has the ability to display a numeric key, a secure socket connection is not possible. In such a case, use {#link createInsecureRfcommSocket}. For more details, refer to the Security Model section 5.2 (vol 3) of Bluetooth Core Specification version 2.1 + EDR.
Use BluetoothSocket.connect()
to initiate the outgoing
connection.
Valid L2CAP PSM channels are in range 1 to 2^16.
Requires android.Manifest.permission#BLUETOOTH
channel
- L2cap PSM/channel to connect toIOException
- on error, for example Bluetooth not available, or
insufficient permissionspublic BluetoothSocket createRfcommSocketToServiceRecord(UUID uuid) throws IOException
BluetoothSocket
ready to start a secure
outgoing connection to this remote device using SDP lookup of uuid.
This is designed to be used with BluetoothAdapter.listenUsingRfcommWithServiceRecord(java.lang.String, java.util.UUID)
for peer-peer
Bluetooth applications.
Use BluetoothSocket.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.
Use this socket only if an authenticated socket link is possible. Authentication refers to the authentication of the link key to prevent man-in-the-middle type of attacks. For example, for Bluetooth 2.1 devices, if any of the devices does not have an input and output capability or just has the ability to display a numeric key, a secure socket connection is not possible. In such a case, use {#link createInsecureRfcommSocketToServiceRecord}. For more details, refer to the Security Model section 5.2 (vol 3) of Bluetooth Core Specification version 2.1 + EDR.
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 android.Manifest.permission#BLUETOOTH
uuid
- service record uuid to lookup RFCOMM channelIOException
- on error, for example Bluetooth not available, or
insufficient permissionspublic BluetoothSocket createInsecureRfcommSocketToServiceRecord(UUID uuid) throws IOException
BluetoothSocket
socket ready to start an insecure
outgoing connection to this remote device using SDP lookup of uuid.
The communication channel will not have an authenticated link key
i.e it will be subject to man-in-the-middle attacks. For Bluetooth 2.1
devices, the link key will be encrypted, as encryption is mandatory.
For legacy devices (pre Bluetooth 2.1 devices) the link key will
be not be encrypted. Use createRfcommSocketToServiceRecord(java.util.UUID)
if an
encrypted and authenticated communication channel is desired.
This is designed to be used with BluetoothAdapter.listenUsingInsecureRfcommWithServiceRecord(java.lang.String, java.util.UUID)
for peer-peer
Bluetooth applications.
Use BluetoothSocket.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 android.Manifest.permission#BLUETOOTH
uuid
- service record uuid to lookup RFCOMM channelIOException
- on error, for example Bluetooth not available, or
insufficient permissionspublic BluetoothSocket createInsecureRfcommSocket(int port) throws IOException
Requires android.Manifest.permission#BLUETOOTH_ADMIN
port
- remote portIOException
- On error, for example Bluetooth not available, or
insufficient permissions.public BluetoothSocket createScoSocket() throws IOException
Requires android.Manifest.permission#BLUETOOTH_ADMIN
IOException
- on error, for example Bluetooth not available, or
insufficient permissions.public static byte[] convertPinToBytes(String pin)
pin
- pin as java Stringpublic BluetoothGatt connectGatt(Context context, boolean autoConnect, BluetoothGattCallback callback)
callback
- GATT callback handler that will receive asynchronous callbacks.autoConnect
- Whether to directly connect to the remote device (false)
or to automatically connect as soon as the remote
device becomes available (true).IllegalArgumentException
- if callback is nullpublic BluetoothGatt connectGatt(Context context, boolean autoConnect, BluetoothGattCallback callback, int transport)
callback
- GATT callback handler that will receive asynchronous callbacks.autoConnect
- Whether to directly connect to the remote device (false)
or to automatically connect as soon as the remote
device becomes available (true).transport
- preferred transport for GATT connections to remote dual-mode devices
TRANSPORT_AUTO
or
TRANSPORT_BREDR
or TRANSPORT_LE
IllegalArgumentException
- if callback is null