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 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_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 |
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 |
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_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 |
static String |
EXTRA_PAIRING_VARIANT |
static String |
EXTRA_PREVIOUS_BOND_STATE
Used as an int extra field in
ACTION_BOND_STATE_CHANGED intents. |
static String |
EXTRA_REASON |
static String |
EXTRA_RSSI
Used as an optional short extra field in
ACTION_FOUND intents. |
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
|
static int |
PAIRING_VARIANT_PIN
The user will be prompted to enter a pin
|
static int |
REQUEST_TYPE_PHONEBOOK_ACCESS |
static int |
REQUEST_TYPE_PROFILE_CONNECTION |
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_WRITE_RETURN_VALUE
Modifier and Type | Method and Description |
---|---|
boolean |
cancelBondProcess()
Cancel an in-progress bonding request started with
createBond() . |
boolean |
cancelPairingUserInput() |
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 |
createBondOutOfBand(byte[] hash,
byte[] randomizer)
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 |
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's
marshalled representation.
|
boolean |
equals(Object o)
Compares this instance with the specified object and indicates if they
are equal.
|
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.
|
String |
getName()
Get the friendly Bluetooth name of the remote device.
|
int |
getServiceChannel(ParcelUuid uuid) |
boolean |
getTrustState()
Get trust state of a remote device.
|
ParcelUuid[] |
getUuids()
Returns the supported features (UUIDs) of the remote device.
|
int |
hashCode()
Returns an integer hash code for this object.
|
boolean |
isBluetoothDock() |
boolean |
removeBond()
Remove bond (pairing) with the remote device.
|
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 |
setPairingConfirmation(boolean confirm) |
boolean |
setPasskey(int passkey) |
boolean |
setPin(byte[] pin) |
boolean |
setRemoteOutOfBandData() |
boolean |
setTrust(boolean value)
Set trust state for a remote 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
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}
,
Constant Field Valuespublic 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
public static final String EXTRA_PAIRING_VARIANT
public static final String EXTRA_PAIRING_KEY
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_NAME_FAILED
Always contains the extra field EXTRA_DEVICE
.
Requires android.Manifest.permission#BLUETOOTH
to receive.
public static final String ACTION_PAIRING_REQUEST
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 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 String EXTRA_UUID
ACTION_UUID
intents,
Contains the ParcelUuid
s of the remote device which
is a parcelable version of UUID
.public static final Parcelable.Creator<BluetoothDevice> CREATOR
public boolean equals(Object o)
Object
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 Object.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.
equals
in class Object
o
- the object to compare this instance with.true
if the specified object is equal to this Object
; false
otherwise.Object.hashCode()
public int hashCode()
Object
Object.equals(java.lang.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.
hashCode
in class Object
Object.equals(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
describeContents
in interface Parcelable
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 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 createBondOutOfBand(byte[] hash, byte[] randomizer)
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
.
hash
- - Simple Secure pairing hashrandomizer
- - The random key obtained using OOBpublic 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 BluetoothClass getBluetoothClass()
Requires android.Manifest.permission#BLUETOOTH
.
public boolean getTrustState()
Requires android.Manifest.permission#BLUETOOTH
.
public boolean setTrust(boolean value)
Requires android.Manifest.permission#BLUETOOTH_ADMIN
.
value
- the trust state value (true or false)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 int getServiceChannel(ParcelUuid uuid)
public boolean setPin(byte[] pin)
public boolean setPasskey(int passkey)
public boolean setPairingConfirmation(boolean confirm)
public boolean setRemoteOutOfBandData()
public boolean cancelPairingUserInput()
public boolean isBluetoothDock()
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 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 String