Java android bluetooth device

Содержание
  1. BluetoothDevice
  2. Developer Guides
  3. Summary
  4. Constants
  5. public static final String ACTION_ACL_CONNECTED
  6. public static final String ACTION_ACL_DISCONNECTED
  7. public static final String ACTION_ACL_DISCONNECT_REQUESTED
  8. public static final String ACTION_BOND_STATE_CHANGED
  9. public static final String ACTION_CLASS_CHANGED
  10. public static final String ACTION_FOUND
  11. public static final String ACTION_NAME_CHANGED
  12. public static final String ACTION_PAIRING_REQUEST
  13. public static final String ACTION_UUID
  14. public static final int BOND_BONDED
  15. public static final int BOND_BONDING
  16. public static final int BOND_NONE
  17. public static final int DEVICE_TYPE_CLASSIC
  18. public static final int DEVICE_TYPE_DUAL
  19. public static final int DEVICE_TYPE_LE
  20. public static final int DEVICE_TYPE_UNKNOWN
  21. public static final int ERROR
  22. public static final String EXTRA_BOND_STATE
  23. public static final String EXTRA_CLASS
  24. public static final String EXTRA_DEVICE
  25. public static final String EXTRA_NAME
  26. public static final String EXTRA_PAIRING_KEY
  27. public static final String EXTRA_PAIRING_VARIANT
  28. public static final String EXTRA_PREVIOUS_BOND_STATE
  29. public static final String EXTRA_RSSI
  30. public static final String EXTRA_UUID
  31. public static final int PAIRING_VARIANT_PASSKEY_CONFIRMATION
  32. public static final int PAIRING_VARIANT_PIN
  33. Fields
  34. public static final Creator CREATOR
  35. Public Methods
  36. public BluetoothGatt connectGatt (Context context, boolean autoConnect, BluetoothGattCallback callback)
  37. public boolean createBond ()
  38. public BluetoothSocket createInsecureRfcommSocketToServiceRecord (UUID uuid)
  39. public BluetoothSocket createRfcommSocketToServiceRecord (UUID uuid)

BluetoothDevice

Represents a remote Bluetooth device. A BluetoothDevice lets you create a connection with the respective device or query information about it, such as the name, address, class, and bonding state.

This class is really just a thin wrapper for a Bluetooth hardware address. Objects of this class are immutable. Operations on this class are performed on the remote Bluetooth hardware address, using the BluetoothAdapter that was used to create this BluetoothDevice .

To get a BluetoothDevice , use BluetoothAdapter.getRemoteDevice(String) to create one representing a device of a known MAC address (which you can get through device discovery with BluetoothAdapter ) or get one from the set of bonded devices returned by BluetoothAdapter.getBondedDevices() . You can then open a BluetoothSocket for communication with the remote device, using createRfcommSocketToServiceRecord(UUID) .

Note: Requires the BLUETOOTH permission.

Developer Guides

For more information about using Bluetooth, read the Bluetooth developer guide.

See Also

Summary

Constants
String ACTION_ACL_CONNECTED Broadcast Action: Indicates a low level (ACL) connection has been established with a remote device.
String ACTION_ACL_DISCONNECTED Broadcast Action: Indicates a low level (ACL) disconnection from a remote device.
String ACTION_ACL_DISCONNECT_REQUESTED Broadcast Action: Indicates that a low level (ACL) disconnection has been requested for a remote device, and it will soon be disconnected.
String ACTION_BOND_STATE_CHANGED Broadcast Action: Indicates a change in the bond state of a remote device.
String ACTION_CLASS_CHANGED Broadcast Action: Bluetooth class of a remote device has changed.
String ACTION_FOUND Broadcast Action: Remote device discovered.
String ACTION_NAME_CHANGED Broadcast Action: Indicates the friendly name of a remote device has been retrieved for the first time, or changed since the last retrieval.
String ACTION_PAIRING_REQUEST Broadcast Action: This intent is used to broadcast PAIRING REQUEST
int CONTENTS_FILE_DESCRIPTOR Bit masks for use with describeContents() : each bit represents a kind of object considered to have potential special significance when marshalled.
int PARCELABLE_WRITE_RETURN_VALUE Flag for use with writeToParcel(Parcel, int) : the object being written is a return value, that is the result of a function such as » Parcelable someFunction() «, » void someFunction(out Parcelable) «, or » void someFunction(inout Parcelable) «.

Create an RFCOMM BluetoothSocket socket ready to start an insecure outgoing connection to this remote device using SDP lookup of uuid.

Create an RFCOMM BluetoothSocket ready to start a secure outgoing connection to this remote device using SDP lookup of uuid.

Causes a thread which is waiting on this object’s monitor (by means of calling one of the wait() methods) to be woken up.

Causes all threads which are waiting on this object’s monitor (by means of calling one of the wait() methods) to be woken up.

Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object.

Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the specified timeout expires.

Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the specified timeout expires.

Constants

public static final String 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.

public static final String 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.

public static final 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.

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 .

public static final String 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).

public static final String ACTION_CLASS_CHANGED

Broadcast Action: Bluetooth class of a remote device has changed.

Always contains the extra fields EXTRA_DEVICE and EXTRA_CLASS .

See Also

public static final String ACTION_FOUND

Broadcast Action: Remote device discovered.

Sent when a remote device is found during discovery.

Always contains the extra fields EXTRA_DEVICE and EXTRA_CLASS . Can contain the extra fields EXTRA_NAME and/or EXTRA_RSSI if they are available.

public static final 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.

Always contains the extra fields EXTRA_DEVICE and EXTRA_NAME .

public static final String ACTION_PAIRING_REQUEST

Broadcast Action: This intent is used to broadcast PAIRING REQUEST

public static final 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. 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

public static final int 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.

public static final int BOND_BONDING

Indicates bonding (pairing) is in progress with the remote device.

public static final int 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.

public static final int DEVICE_TYPE_CLASSIC

Bluetooth device type, Classic — BR/EDR devices

public static final int DEVICE_TYPE_DUAL

Bluetooth device type, Dual Mode — BR/EDR/LE

public static final int DEVICE_TYPE_LE

Bluetooth device type, Low Energy — LE-only

public static final int DEVICE_TYPE_UNKNOWN

Bluetooth device type, Unknown

public static final int 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:

public static final String EXTRA_BOND_STATE

Used as an int extra field in ACTION_BOND_STATE_CHANGED intents. Contains the bond state of the remote device.

public static final String EXTRA_CLASS

Used as a Parcelable BluetoothClass extra field in ACTION_FOUND and ACTION_CLASS_CHANGED intents.

public static final String EXTRA_DEVICE

Used as a Parcelable 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

Used as a String extra field in ACTION_NAME_CHANGED and ACTION_FOUND intents. It contains the friendly Bluetooth name.

public static final String EXTRA_PAIRING_KEY

Used as an int extra field in ACTION_PAIRING_REQUEST intents as the value of passkey.

public static final String EXTRA_PAIRING_VARIANT

Used as an int extra field in ACTION_PAIRING_REQUEST intents to indicate pairing method used. Possible values are: PAIRING_VARIANT_PIN , PAIRING_VARIANT_PASSKEY_CONFIRMATION ,

public static final String EXTRA_PREVIOUS_BOND_STATE

Used as an int extra field in ACTION_BOND_STATE_CHANGED intents. Contains the previous bond state of the remote device.

public static final String EXTRA_RSSI

Used as an optional short extra field in ACTION_FOUND intents. Contains the RSSI value of the remote device as reported by the Bluetooth hardware.

public static final 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 .

public static final 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.

public static final int PAIRING_VARIANT_PIN

The user will be prompted to enter a pin or an app will enter a pin for user.

Fields

public static final Creator CREATOR

Public Methods

public BluetoothGatt 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
Throws

public boolean createBond ()

Start the bonding (pairing) process with the remote device.

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.

Returns

public 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.

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.

Parameters
Returns
Throws

public BluetoothSocket createRfcommSocketToServiceRecord (UUID uuid)

Create an RFCOMM BluetoothSocket ready to start a secure outgoing connection to this remote device using SDP lookup of uuid.

This is designed to be used with listenUsingRfcommWithServiceRecord(String, UUID) for peer-peer Bluetooth applications.

Use connect() to initiate the outgoing connection. This will also perform an SDP lookup of the given uuid to determine which channel to connect to.

The remote device will be authenticated and communication on this socket will be encrypted.

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 . 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.

Parameters
Returns

Источник

Читайте также:  Bluetooth earbud for iphone
Оцените статью
Adblock
detector