android-BluetoothDevice
2016-07-19 11:10
447 查看
BluetoothDevice
public final class BluetoothDevice
extends Object
implements Parcelable
java.lang.Object | |
↳ | android.bluetooth.BluetoothDevice |
BluetoothDevicelets you create a connection
with the respective device or query information about it, such as the name, address, class, and bonding state.
代表一个远程蓝牙设备。BluetoothDevice允许您创建一个连接与各自的设备或查询相关信息,如名称、地址、类和连接状态。
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
BluetoothAdapterthat
was used to create this
BluetoothDevice.
这个类只是蓝牙硬件地址的详细包装器。这个类的对象是不可变的。操作这类上执行远程蓝牙硬件地址,使用BluetoothAdapter用于创建这个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
BluetoothSocketfor communication with the remote device,
using
createRfcommSocketToServiceRecord(UUID).
得到一个BluetoothDevice,使用BluetoothAdapter.getRemoteDevice(String)来创建一个代表一个设备的一个已知的MAC地址(您可以通过设备发现BluetoothAdapter)或从组获得一个已配对设备返回BluetoothAdapter.getBondedDevices()。你可以打开一个BluetoothSocket与远程设备进行通信,使用createRfcommSocketToServiceRecord(UUID)。
Note: Requires the
BLUETOOTHpermission.
Developer Guides
For more information about using Bluetooth, read the Bluetooth developerguide.
See also:
BluetoothAdapter
BluetoothSocket
Summary
| |
---|---|
String | ACTION_ACL_CONNECTED Broadcast Action: Indicates a low level (ACL) connection has been established with a remote device. 表明低水平(ACL)与远程设备连接已经建立。 |
String | ACTION_ACL_DISCONNECTED Broadcast Action: Indicates a low level (ACL) disconnection from a remote device. 表明低水平(ACL)从远程设备断开连接。 |
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. 表明低水平(ACL)的一个远程设备断开了请求,它很快就会断开连接。 |
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. |
String | ACTION_PAIRING_REQUEST Broadcast Action: This intent is used to broadcast PAIRING REQUEST Requires BLUETOOTH_ADMINto receive. |
String | ACTION_UUID Broadcast Action: This intent is used to broadcast the UUIDwrapped as a ParcelUuidof the remote device after it has been fetched. |
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). |
int | DEVICE_TYPE_CLASSIC Bluetooth device type, Classic - BR/EDR devices |
int | DEVICE_TYPE_DUAL Bluetooth device type, Dual Mode - BR/EDR/LE |
int | DEVICE_TYPE_LE Bluetooth device type, Low Energy - LE-only |
int | DEVICE_TYPE_UNKNOWN Bluetooth device type, Unknown |
int | ERROR Sentinel error value for this class. |
String | EXTRA_BOND_STATE Used as an int extra field in ACTION_BOND_STATE_CHANGEDintents. |
String | EXTRA_CLASS Used as a Parcelable BluetoothClassextra field in ACTION_FOUNDand ACTION_CLASS_CHANGEDintents. |
String | EXTRA_DEVICE Used as a Parcelable BluetoothDeviceextra field in every intent broadcast by this class. |
String | EXTRA_NAME Used as a String extra field in ACTION_NAME_CHANGEDand ACTION_FOUNDintents. |
String | EXTRA_PAIRING_KEY Used as an int extra field in ACTION_PAIRING_REQUESTintents as the value of passkey. |
String | EXTRA_PAIRING_VARIANT Used as an int extra field in ACTION_PAIRING_REQUESTintents to indicate pairing method used. |
String | EXTRA_PREVIOUS_BOND_STATE Used as an int extra field in ACTION_BOND_STATE_CHANGEDintents. |
String | EXTRA_RSSI Used as an optional short extra field in ACTION_FOUNDintents. |
String | EXTRA_UUID Used as an extra field in ACTION_UUIDintents, Contains the ParcelUuids of the remote device which is a parcelable version of UUID. |
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. |
int | PAIRING_VARIANT_PIN The user will be prompted to enter a pin or an app will enter a pin for user. |
int | TRANSPORT_AUTO No preferrence of physical transport for GATT connections to remote dual-mode devices |
int | TRANSPORT_BREDR Prefer BR/EDR transport for GATT connections to remote dual-mode devices |
int | TRANSPORT_LE Prefer LE transport for GATT connections to remote dual-mode devices |
|
---|
![]() From interface android.os.Parcelable |
| |
---|---|
public static finalCreator<BluetoothDevice> | CREATOR |
| |
---|---|
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. |
boolean | createBond() Start the bonding (pairing) process with the remote device. |
BluetoothSocket | createInsecureRfcommSocketToServiceRecord(UUID uuid) Create an RFCOMM BluetoothSocketsocket ready to start an insecure outgoing connection to this remote device using SDP lookup of uuid. |
BluetoothSocket | createRfcommSocketToServiceRecord(UUID uuid) Create an RFCOMM BluetoothSocketready to start a secure outgoing connection to this remote device using SDP lookup of uuid. |
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. |
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 | 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 | setPairingConfirmation(boolean confirm) Confirm passkey for PAIRING_VARIANT_PASSKEY_CONFIRMATIONpairing. |
boolean | setPin(byte[] pin) Set the pin during pairing when the pairing method is PAIRING_VARIANT_PIN Requires BLUETOOTH_ADMIN. |
String | toString() Returns a string representation of this BluetoothDevice. |
void | writeToParcel(Parcel out, int flags) Flatten this object in to a Parcel. |
|
---|
![]() From class java.lang.Object |
![]() From interface android.os.Parcelable |
Constants
ACTION_ACL_CONNECTED
Added in API level 5String ACTION_ACL_CONNECTED
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
BLUETOOTHto receive.
Constant Value: "android.bluetooth.device.action.ACL_CONNECTED"
ACTION_ACL_DISCONNECTED
Added in API level 5String ACTION_ACL_DISCONNECTED
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
BLUETOOTHto receive.
Constant Value: "android.bluetooth.device.action.ACL_DISCONNECTED"
ACTION_ACL_DISCONNECT_REQUESTED
Added in API level 5String 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.
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
BLUETOOTHto receive.
Constant Value: "android.bluetooth.device.action.ACL_DISCONNECT_REQUESTED"
ACTION_BOND_STATE_CHANGED
Added in API level 5String ACTION_BOND_STATE_CHANGED
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_STATEand
EXTRA_PREVIOUS_BOND_STATE.
Requires
BLUETOOTHto receive.
Constant Value: "android.bluetooth.device.action.BOND_STATE_CHANGED"
ACTION_CLASS_CHANGED
Added in API level 5String ACTION_CLASS_CHANGED
Broadcast Action: Bluetooth class of a remote device has changed.
Always contains the extra fields
EXTRA_DEVICEand
EXTRA_CLASS.
Requires
BLUETOOTHto receive.
See also:
BluetoothClass
Constant Value: "android.bluetooth.device.action.CLASS_CHANGED"
ACTION_FOUND
Added in API level 5String ACTION_FOUND
Broadcast Action: Remote device discovered.
Sent when a remote device is found during discovery.
Always contains the extra fields
EXTRA_DEVICEand
EXTRA_CLASS.
Can contain the extra fields
EXTRA_NAMEand/or
EXTRA_RSSIif
they are available.
Requires
BLUETOOTHand
ACCESS_COARSE_LOCATIONto
receive.
Constant Value: "android.bluetooth.device.action.FOUND"
ACTION_NAME_CHANGED
Added in API level 5String 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.
Always contains the extra fields
EXTRA_DEVICEand
EXTRA_NAME.
Requires
BLUETOOTHto receive.
Constant Value: "android.bluetooth.device.action.NAME_CHANGED"
ACTION_PAIRING_REQUEST
Added in API level 19String ACTION_PAIRING_REQUEST
Broadcast Action: This intent is used to broadcast PAIRING REQUEST
Requires
BLUETOOTH_ADMINto
receive.
Constant Value: "android.bluetooth.device.action.PAIRING_REQUEST"
ACTION_UUID
Added in API level 15String ACTION_UUID
Broadcast Action: This intent is used to broadcast the
UUIDwrapped
as a
ParcelUuidof 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
BLUETOOTHto receive.
Constant Value: "android.bluetooth.device.action.UUID"
BOND_BONDED
Added in API level 5int BOND_BONDED
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.
Constant Value: 12 (0x0000000c)
BOND_BONDING
Added in API level 5int BOND_BONDING
Indicates bonding (pairing) is in progress with the remote device.
Constant Value: 11 (0x0000000b)
BOND_NONE
Added in API level 5int BOND_NONE
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.
Constant Value: 10 (0x0000000a)
DEVICE_TYPE_CLASSIC
Added in API level 18int DEVICE_TYPE_CLASSIC
Bluetooth device type, Classic - BR/EDR devices
Constant Value: 1 (0x00000001)
DEVICE_TYPE_DUAL
Added in API level 18int DEVICE_TYPE_DUAL
Bluetooth device type, Dual Mode - BR/EDR/LE
Constant Value: 3 (0x00000003)
DEVICE_TYPE_LE
Added in API level 18int DEVICE_TYPE_LE
Bluetooth device type, Low Energy - LE-only
Constant Value: 2 (0x00000002)
DEVICE_TYPE_UNKNOWN
Added in API level 18int DEVICE_TYPE_UNKNOWN
Bluetooth device type, Unknown
Constant Value: 0 (0x00000000)
ERROR
Added in API level 5int ERROR
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)
Constant Value: -2147483648 (0x80000000)
EXTRA_BOND_STATE
Added in API level 5String EXTRA_BOND_STATE
Used as an int extra field in
ACTION_BOND_STATE_CHANGEDintents.
Contains the bond state of the remote device.
Possible values are:
BOND_NONE,
BOND_BONDING,
BOND_BONDED.
Constant Value: "android.bluetooth.device.extra.BOND_STATE"
EXTRA_CLASS
Added in API level 5String EXTRA_CLASS
Used as a Parcelable
BluetoothClassextra
field in
ACTION_FOUNDand
ACTION_CLASS_CHANGEDintents.
Constant Value: "android.bluetooth.device.extra.CLASS"
EXTRA_DEVICE
Added in API level 5String EXTRA_DEVICE
Used as a Parcelable
BluetoothDeviceextra
field in every intent broadcast by this class. It contains the
BluetoothDevicethat
the intent applies to.
Constant Value: "android.bluetooth.device.extra.DEVICE"
EXTRA_NAME
Added in API level 5String EXTRA_NAME
Used as a String extra field in
ACTION_NAME_CHANGEDand
ACTION_FOUNDintents.
It contains the friendly Bluetooth name.
Constant Value: "android.bluetooth.device.extra.NAME"
EXTRA_PAIRING_KEY
Added in API level 19String EXTRA_PAIRING_KEY
Used as an int extra field in
ACTION_PAIRING_REQUESTintents
as the value of passkey.
Constant Value: "android.bluetooth.device.extra.PAIRING_KEY"
EXTRA_PAIRING_VARIANT
Added in API level 19String EXTRA_PAIRING_VARIANT
Used as an int extra field in
ACTION_PAIRING_REQUESTintents
to indicate pairing method used. Possible values are:
PAIRING_VARIANT_PIN,
PAIRING_VARIANT_PASSKEY_CONFIRMATION,
Constant Value: "android.bluetooth.device.extra.PAIRING_VARIANT"
EXTRA_PREVIOUS_BOND_STATE
Added in API level 5String EXTRA_PREVIOUS_BOND_STATE
Used as an int extra field in
ACTION_BOND_STATE_CHANGEDintents.
Contains the previous bond state of the remote device.
Possible values are:
BOND_NONE,
BOND_BONDING,
BOND_BONDED.
Constant Value: "android.bluetooth.device.extra.PREVIOUS_BOND_STATE"
EXTRA_RSSI
Added in API level 5String EXTRA_RSSI
Used as an optional short extra field in
ACTION_FOUNDintents.
Contains the RSSI value of the remote device as reported by the Bluetooth hardware.
Constant Value: "android.bluetooth.device.extra.RSSI"
EXTRA_UUID
Added in API level 15String EXTRA_UUID
Used as an extra field in
ACTION_UUIDintents,
Contains the
ParcelUuids of the remote device which is a parcelable version of
UUID.
Constant Value: "android.bluetooth.device.extra.UUID"
PAIRING_VARIANT_PASSKEY_CONFIRMATION
Added in API level 19int 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.
Constant Value: 2 (0x00000002)
PAIRING_VARIANT_PIN
Added in API level 19int PAIRING_VARIANT_PIN
The user will be prompted to enter a pin or an app will enter a pin for user.
Constant Value: 0 (0x00000000)
TRANSPORT_AUTO
Added in API level 23int TRANSPORT_AUTO
No preferrence of physical transport for GATT connections to remote dual-mode devices
Constant Value: 0 (0x00000000)
TRANSPORT_BREDR
Added in API level 23int TRANSPORT_BREDR
Prefer BR/EDR transport for GATT connections to remote dual-mode devices
Constant Value: 1 (0x00000001)
TRANSPORT_LE
Added in API level 23int TRANSPORT_LE
Prefer LE transport for GATT connections to remote dual-mode devices
Constant Value: 2 (0x00000002)
Fields
CREATOR
Added in API level 5Creator<BluetoothDevice> CREATOR
Public methods
connectGatt
Added in API level 18BluetoothGatt connectGatt (Context context, boolean autoConnect, BluetoothGattCallback callback)
Connect to GATT Server hosted by this device. Caller acts as GATT client. The callback is used to deliver results to Caller, such as connection status as well as any further GATT client operations. The method returns
a BluetoothGatt instance. You can use BluetoothGatt to conduct GATT client operations.
Parameters | |
---|---|
context | Context |
autoConnect | boolean: Whether to directly connect to the remote device (false) or to automatically connect as soon as the remote device becomes available (true). |
callback | BluetoothGattCallback: GATT callback handler that will receive asynchronous callbacks. |
Returns | |
---|---|
BluetoothGatt |
Throws | |
---|---|
IllegalArgumentException | if callback is null |
connectGatt
Added in API level 23BluetoothGatt connectGatt (Context context, boolean autoConnect, BluetoothGattCallback callback, int transport)
Connect to GATT Server hosted by this device. Caller acts as GATT client. The callback is used to deliver results to Caller, such as connection status as well as any further GATT client operations. The method returns
a BluetoothGatt instance. You can use BluetoothGatt to conduct GATT client operations.
Parameters | |
---|---|
context | Context |
autoConnect | boolean: Whether to directly connect to the remote device (false) or to automatically connect as soon as the remote device becomes available (true). |
callback | BluetoothGattCallback: GATT callback handler that will receive asynchronous callbacks. |
transport | int: preferred transport for GATT connections to remote dual-mode devices TRANSPORT_AUTOor TRANSPORT_BREDRor TRANSPORT_LE |
Returns | |
---|---|
BluetoothGatt |
Throws | |
---|---|
IllegalArgumentException | if callback is null |
createBond
Added in API level 19boolean createBond ()
Start the bonding (pairing) process with the remote device.
This is an asynchronous call, it will return immediately. Register for
ACTION_BOND_STATE_CHANGEDintents
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
BLUETOOTH_ADMIN.
Returns | |
---|---|
boolean | false on immediate error, true if bonding will begin |
createInsecureRfcommSocketToServiceRecord
Added in API level 10BluetoothSocket createInsecureRfcommSocketToServiceRecord (UUID uuid)
Create an RFCOMM
BluetoothSocketsocket
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(UUID)if
an encrypted and authenticated communication channel is desired.
This is designed to be used with
listenUsingInsecureRfcommWithServiceRecord(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
Parameters | |
---|---|
uuid | UUID: service record uuid to lookup RFCOMM channel |
Returns | |
---|---|
BluetoothSocket | a RFCOMM BluetoothServerSocket ready for an outgoing connection |
Throws | |
---|---|
IOException | on error, for example Bluetooth not available, or insufficient permissions |
createRfcommSocketToServiceRecord
Added in API level 5BluetoothSocket createRfcommSocketToServiceRecord (UUID uuid)
Create an RFCOMM
BluetoothSocketready
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.
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
BLUETOOTH
Parameters | |
---|---|
uuid | UUID: service record uuid to lookup RFCOMM channel |
Returns | |
---|---|
BluetoothSocket | a RFCOMM BluetoothServerSocket ready for an outgoing connection |
Throws | |
---|---|
IOException | on error, for example Bluetooth not available, or insufficient permissions |
describeContents
Added in API level 5int describeContents ()
Describe the kinds of special objects contained in this Parcelable instance's marshaled representation. For example, if the object will include a file descriptor in the output of
writeToParcel(Parcel, int), the return value of this method must include the
CONTENTS_FILE_DESCRIPTORbit.
Returns | |
---|---|
int | a bitmask indicating the set of special object types marshaled by this Parcelable object instance. |
equals
Added in API level 5boolean equals (Object o)
Indicates whether some other object is "equal to" this one.
The
equalsmethod implements an equivalence relation on non-null object references:
It is reflexive: for any non-null reference value
x,
x.equals(x)should return
true.
It is symmetric: for any non-null reference values
xand
y,
x.equals(y)should return
trueif and only if
y.equals(x)returns
true.
It is transitive: for any non-null reference values
x,
y, and
z, if
x.equals(y)returns
trueand
y.equals(z)returns
true,
then
x.equals(z)should return
true.
It is consistent: for any non-null reference values
xand
y, multiple invocations of
x.equals(y)consistently return
trueor consistently
return
false, provided no information used in
equalscomparisons on the objects is modified.
For any non-null reference value
x,
x.equals(null)should return
false.
The
equalsmethod for class
Objectimplements the most discriminating possible equivalence relation on objects; that is, for any non-null reference values
xand
y,
this method returns
trueif and only if
xand
yrefer to the same object (
x == yhas the value
true).
Note that it is generally necessary to override the
hashCodemethod whenever this method is overridden, so as to maintain the general contract for the
hashCodemethod,
which states that equal objects must have equal hash codes.
Parameters | |
---|---|
o | Object: the reference object with which to compare. |
Returns | |
---|---|
boolean | trueif this object is the same as the obj argument; falseotherwise. |
fetchUuidsWithSdp
Added in API level 15boolean fetchUuidsWithSdp ()
Perform a service discovery on the remote device to get the UUIDs supported.
This API is asynchronous and
ACTION_UUIDintent
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_UUIDintent
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
BLUETOOTH.
Returns | |
---|---|
boolean | False if the sanity check fails, True if the process of initiating an ACL connection to the remote device was started. |
getAddress
Added in API level 5String getAddress ()
Returns the hardware address of this BluetoothDevice.
For example, "00:11:22:AA:BB:CC".
Returns | |
---|---|
String | Bluetooth hardware address as string |
getBluetoothClass
Added in API level 5BluetoothClass getBluetoothClass ()
Get the Bluetooth class of the remote device.
Requires
BLUETOOTH.
Returns | |
---|---|
BluetoothClass | Bluetooth class object, or null on error |
getBondState
Added in API level 5int getBondState ()
Get the bond state of the remote device.
Possible values for the bond state are:
BOND_NONE,
BOND_BONDING,
BOND_BONDED.
Requires
BLUETOOTH.
Returns | |
---|---|
int | the bond state |
getName
Added in API level 5String getName ()
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 | |
---|---|
String | the Bluetooth name, or null if there was a problem. |
getType
Added in API level 18int getType ()
Get the Bluetooth device type of the remote device.
Requires
BLUETOOTH
Returns | |
---|---|
int | the device type DEVICE_TYPE_CLASSIC, DEVICE_TYPE_LE DEVICE_TYPE_DUAL. DEVICE_TYPE_UNKNOWNif it's not available |
getUuids
Added in API level 15ParcelUuid[] getUuids ()
Returns the supported features (UUIDs) of the remote device.
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
BLUETOOTH.
Returns | |
---|---|
ParcelUuid[] | the supported features (UUIDs) of the remote device, or null on error |
hashCode
Added in API level 5int hashCode ()
Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by
HashMap.
The general contract of
hashCodeis:
Whenever it is invoked on the same object more than once during an execution of a Java application, the
hashCodemethod must consistently return the same integer, provided no information used in
equalscomparisons
on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
If two objects are equal according to the
equals(Object)method, then calling the
hashCodemethod on each of the two objects must produce the same integer result.
It is not required that if two objects are unequal according to the
equals(java.lang.Object)method,
then calling the
hashCodemethod 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
Objectdoes 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 JavaTMprogramming language.)
Returns | |
---|---|
int | a hash code value for this object. |
setPairingConfirmation
Added in API level 19boolean setPairingConfirmation (boolean confirm)
Confirm passkey for
PAIRING_VARIANT_PASSKEY_CONFIRMATIONpairing.
Requires
BLUETOOTH_ADMIN.
Parameters | |
---|---|
confirm | boolean |
Returns | |
---|---|
boolean | true confirmation has been sent out false for error |
setPin
Added in API level 19boolean setPin (byte[] pin)
Set the pin during pairing when the pairing method is
PAIRING_VARIANT_PIN
Requires
BLUETOOTH_ADMIN.
Parameters | |
---|---|
pin | byte |
Returns | |
---|---|
boolean | true pin has been set false for error |
toString
Added in API level 5String toString ()
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.
Returns | |
---|---|
String | string representation of this BluetoothDevice |
writeToParcel
Added in API level 5void writeToParcel (Parcel out, int flags)
Flatten this object in to a Parcel.
Parameters | |
---|---|
out | Parcel: The Parcel in which the object should be written. |
flags | int: Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE. |
相关文章推荐
- UIButton实现左文字右图片
- iOS开发从入门到精通--开关按钮UISwitch控件
- Android studio value 2 (com.android.dex.DexException:资源重复引用或者加载问题)
- iOS开发runtime给工程所有UITextfield属性赋初值
- [转]java.sql.SQLException: Incorrect string value: '\xF0\x9F\x98\x8E' for column 'nick' at row 1
- 基于java容器注解说明---@Value和@ImportResource
- servlet request getHeader(“x-forwarded-for”) 获取真实IP
- [SQL优化工具]Quest.Central.For.Databases——SQL Tuning for SQL Server
- EL表达式从request和session中取值
- android中requestFocus
- android-UUID
- SpannableString与SpannableStringBuilder使用
- EasyUI中在表单提交之前进行验证
- ZZULUI-1183平面点排序(一)(结构体专题)
- requestAnimationFrame代替setTimeout
- NV Oblique Frustum Clipping demo
- Oblique View Frustum
- 关于UE4.12打包后无法切换到VR模式的问题
- iOS--UI之导航控制器与标签控制器
- 第2条:遇到多个构造器参数时要考虑用构造器