IT. Expert System.

Android Reference

BluetoothDevice


android.bluetooth

Class BluetoothDevice

    • Field Detail

      • ERROR

        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:

        Intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, BluetoothDevice.ERROR)

        See Also:
        Constant Field Values
      • ACTION_FOUND

        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.

        Requires android.Manifest.permission#BLUETOOTH to receive.

        See Also:
        Constant Field Values
      • ACTION_DISAPPEARED

        public static final String ACTION_DISAPPEARED
        Broadcast Action: Remote device 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.

        See Also:
        Constant Field Values
      • ACTION_CLASS_CHANGED

        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.

        Requires android.Manifest.permission#BLUETOOTH to receive.

        See Also:
        BluetoothClass}, Constant Field Values
      • ACTION_ACL_CONNECTED

        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.

        Requires android.Manifest.permission#BLUETOOTH to receive.

        See Also:
        Constant Field Values
      • ACTION_ACL_DISCONNECT_REQUESTED

        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.

        Requires android.Manifest.permission#BLUETOOTH to receive.

        See Also:
        Constant Field Values
      • ACTION_ACL_DISCONNECTED

        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.

        Requires android.Manifest.permission#BLUETOOTH to receive.

        See Also:
        Constant Field Values
      • ACTION_NAME_CHANGED

        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.

        Requires android.Manifest.permission#BLUETOOTH to receive.

        See Also:
        Constant Field Values
      • ACTION_ALIAS_CHANGED

        public static final String ACTION_ALIAS_CHANGED
        Broadcast Action: Indicates the alias of a remote device has been changed.

        Always contains the extra field EXTRA_DEVICE.

        Requires android.Manifest.permission#BLUETOOTH to receive.

        See Also:
        Constant Field Values
      • EXTRA_RSSI

        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.
        See Also:
        Constant Field Values
      • BOND_NONE

        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.

        See Also:
        Constant Field Values
      • BOND_BONDING

        public static final int BOND_BONDING
        Indicates bonding (pairing) is in progress with the remote device.
        See Also:
        Constant Field Values
      • BOND_BONDED

        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.

        See Also:
        Constant Field Values
      • ACTION_UUID

        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

        Requires android.Manifest.permission#BLUETOOTH to receive.

        See Also:
        Constant Field Values
      • ACTION_NAME_FAILED

        public static final String ACTION_NAME_FAILED
        Broadcast Action: Indicates a failure to retrieve the name of a remote device.

        Always contains the extra field EXTRA_DEVICE.

        Requires android.Manifest.permission#BLUETOOTH to receive.

        See Also:
        Constant Field Values
      • REQUEST_TYPE_PROFILE_CONNECTION

        public static final int REQUEST_TYPE_PROFILE_CONNECTION
        See Also:
        Constant Field Values
      • REQUEST_TYPE_PHONEBOOK_ACCESS

        public static final int REQUEST_TYPE_PHONEBOOK_ACCESS
        See Also:
        Constant Field Values
      • EXTRA_ALWAYS_ALLOWED

        public static final 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.
        See Also:
        Constant Field Values
      • BOND_SUCCESS

        public static final int BOND_SUCCESS
        A bond attempt succeeded
        See Also:
        Constant Field Values
      • UNBOND_REASON_AUTH_FAILED

        public static final 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
        See Also:
        Constant Field Values
      • UNBOND_REASON_AUTH_REJECTED

        public static final int UNBOND_REASON_AUTH_REJECTED
        A bond attempt failed because the other side explicitly rejected bonding
        See Also:
        Constant Field Values
      • UNBOND_REASON_AUTH_CANCELED

        public static final int UNBOND_REASON_AUTH_CANCELED
        A bond attempt failed because we canceled the bonding process
        See Also:
        Constant Field Values
      • UNBOND_REASON_REMOTE_DEVICE_DOWN

        public static final int UNBOND_REASON_REMOTE_DEVICE_DOWN
        A bond attempt failed because we could not contact the remote device
        See Also:
        Constant Field Values
      • UNBOND_REASON_DISCOVERY_IN_PROGRESS

        public static final int UNBOND_REASON_DISCOVERY_IN_PROGRESS
        A bond attempt failed because a discovery is in progress
        See Also:
        Constant Field Values
      • UNBOND_REASON_AUTH_TIMEOUT

        public static final int UNBOND_REASON_AUTH_TIMEOUT
        A bond attempt failed because of authentication timeout
        See Also:
        Constant Field Values
      • UNBOND_REASON_REPEATED_ATTEMPTS

        public static final int UNBOND_REASON_REPEATED_ATTEMPTS
        A bond attempt failed because of repeated attempts
        See Also:
        Constant Field Values
      • UNBOND_REASON_REMOTE_AUTH_CANCELED

        public static final int UNBOND_REASON_REMOTE_AUTH_CANCELED
        A bond attempt failed because we received an Authentication Cancel by remote end
        See Also:
        Constant Field Values
      • UNBOND_REASON_REMOVED

        public static final int UNBOND_REASON_REMOVED
        An existing bond was explicitly revoked
        See Also:
        Constant Field Values
      • PAIRING_VARIANT_PIN

        public static final int PAIRING_VARIANT_PIN
        The user will be prompted to enter a pin
        See Also:
        Constant Field Values
      • PAIRING_VARIANT_PASSKEY

        public static final int PAIRING_VARIANT_PASSKEY
        The user will be prompted to enter a passkey
        See Also:
        Constant Field Values
      • PAIRING_VARIANT_PASSKEY_CONFIRMATION

        public static final int PAIRING_VARIANT_PASSKEY_CONFIRMATION
        The user will be prompted to confirm the passkey displayed on the screen
        See Also:
        Constant Field Values
      • PAIRING_VARIANT_CONSENT

        public static final int PAIRING_VARIANT_CONSENT
        The user will be prompted to accept or deny the incoming pairing request
        See Also:
        Constant Field Values
      • PAIRING_VARIANT_DISPLAY_PASSKEY

        public static final 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.
        See Also:
        Constant Field Values
      • PAIRING_VARIANT_DISPLAY_PIN

        public static final int PAIRING_VARIANT_DISPLAY_PIN
        The user will be prompted to enter the PIN displayed on remote device. This is used for Bluetooth 2.0 pairing.
        See Also:
        Constant Field Values
      • PAIRING_VARIANT_OOB_CONSENT

        public static final int PAIRING_VARIANT_OOB_CONSENT
        The user will be prompted to accept or deny the OOB pairing request
        See Also:
        Constant Field Values
    • Method Detail

      • equals

        public boolean equals(Object o)
        Description copied from class: Object
        Compares this instance with the specified object and indicates if they are equal. In order to be equal, o must represent the same object as this instance using a class-specific comparison. The general contract is that this comparison should be reflexive, symmetric, and transitive. Also, no object reference other than null is equal to null.

        The default implementation returns true only if this == o. See Writing a correct equals method if you intend implementing your own equals method.

        The general contract for the equals and 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.

        Overrides:
        equals in class Object
        Parameters:
        o - the object to compare this instance with.
        Returns:
        true if the specified object is equal to this Object; false otherwise.
        See Also:
        Object.hashCode()
      • hashCode

        public int hashCode()
        Description copied from class: Object
        Returns an integer hash code for this object. By contract, any two objects for which 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.

        Overrides:
        hashCode in class Object
        Returns:
        this object's hash code.
        See Also:
        Object.equals(java.lang.Object)
      • toString

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

        Overrides:
        toString in class Object
        Returns:
        string representation of this BluetoothDevice
      • describeContents

        public int describeContents()
        Description copied from interface: Parcelable
        Describe the kinds of special objects contained in this Parcelable's marshalled representation.
        Specified by:
        describeContents in interface Parcelable
        Returns:
        a bitmask indicating the set of special object types marshalled by the Parcelable.
      • getAddress

        public String getAddress()
        Returns the hardware address of this BluetoothDevice.

        For example, "00:11:22:AA:BB:CC".

        Returns:
        Bluetooth hardware address as string
      • getName

        public String 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 android.Manifest.permission#BLUETOOTH

        Returns:
        the Bluetooth name, or null if there was a problem.
      • getAlias

        public String getAlias()
        Get the Bluetooth alias of the remote device.

        Alias is the locally modified name of a remote device.

        Returns:
        the Bluetooth alias, or null if no alias or there was a problem
      • setAlias

        public boolean setAlias(String alias)
        Set the Bluetooth alias of the remote device.

        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.

        Returns:
        true on success, false on error
      • getAliasName

        public String getAliasName()
        Get the Bluetooth alias of the remote device. If Alias is null, get the Bluetooth name instead.
        Returns:
        the Bluetooth alias, or null if no alias or there was a problem
        See Also:
        getAlias(), getName()
      • createBond

        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.

        Requires android.Manifest.permission#BLUETOOTH_ADMIN.

        Returns:
        false on immediate error, true if bonding will begin
      • createBondOutOfBand

        public boolean createBondOutOfBand(byte[] hash,
                                  byte[] randomizer)
        Start the bonding (pairing) process with the remote device using the Out Of Band mechanism.

        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.

        Parameters:
        hash - - Simple Secure pairing hash
        randomizer - - The random key obtained using OOB
        Returns:
        false on immediate error, true if bonding will begin
      • setDeviceOutOfBandData

        public boolean setDeviceOutOfBandData(byte[] hash,
                                     byte[] randomizer)
        Set the Out Of Band data for a remote device to be used later in the pairing mechanism. Users can obtain this data through other trusted channels

        Requires android.Manifest.permission#BLUETOOTH_ADMIN.

        Parameters:
        hash - Simple Secure pairing hash
        randomizer - The random key obtained using OOB
        Returns:
        false on error; true otherwise
      • cancelBondProcess

        public boolean cancelBondProcess()
        Cancel an in-progress bonding request started with createBond().

        Requires android.Manifest.permission#BLUETOOTH_ADMIN.

        Returns:
        true on success, false on error
      • removeBond

        public boolean removeBond()
        Remove bond (pairing) with the remote device.

        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.

        Returns:
        true on success, false on error
      • getBondState

        public int getBondState()
        Get the bond state of the remote device.

        Possible values for the bond state are: BOND_NONE, BOND_BONDING, BOND_BONDED.

        Requires android.Manifest.permission#BLUETOOTH.

        Returns:
        the bond state
      • getBluetoothClass

        public BluetoothClass getBluetoothClass()
        Get the Bluetooth class of the remote device.

        Requires android.Manifest.permission#BLUETOOTH.

        Returns:
        Bluetooth class object, or null on error
      • getTrustState

        public boolean getTrustState()
        Get trust state of a remote device.

        Requires android.Manifest.permission#BLUETOOTH.

      • setTrust

        public boolean setTrust(boolean value)
        Set trust state for a remote device.

        Requires android.Manifest.permission#BLUETOOTH_ADMIN.

        Parameters:
        value - the trust state value (true or false)
      • getUuids

        public ParcelUuid[] 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 android.Manifest.permission#BLUETOOTH.

        Returns:
        the supported features (UUIDs) of the remote device, or null on error
      • fetchUuidsWithSdp

        public boolean fetchUuidsWithSdp()
        Perform a service discovery on the remote device to get the UUIDs supported.

        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.

        Returns:
        False if the sanity check fails, True if the process of initiating an ACL connection to the remote device was started.
      • getServiceChannel

        public int getServiceChannel(ParcelUuid uuid)
      • setPin

        public boolean setPin(byte[] pin)
      • setPasskey

        public boolean setPasskey(int passkey)
      • setPairingConfirmation

        public boolean setPairingConfirmation(boolean confirm)
      • setRemoteOutOfBandData

        public boolean setRemoteOutOfBandData()
      • cancelPairingUserInput

        public boolean cancelPairingUserInput()
      • isBluetoothDock

        public boolean isBluetoothDock()
      • createRfcommSocket

        public BluetoothSocket createRfcommSocket(int channel)
                                           throws IOException
        Create an RFCOMM 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

        Parameters:
        channel - RFCOMM channel to connect to
        Returns:
        a RFCOMM BluetoothServerSocket ready for an outgoing connection
        Throws:
        IOException - on error, for example Bluetooth not available, or insufficient permissions
      • createRfcommSocketToServiceRecord

        public BluetoothSocket createRfcommSocketToServiceRecord(UUID uuid)
                                                          throws IOException
        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 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

        Parameters:
        uuid - service record uuid to lookup RFCOMM channel
        Returns:
        a RFCOMM BluetoothServerSocket ready for an outgoing connection
        Throws:
        IOException - on error, for example Bluetooth not available, or insufficient permissions
      • createInsecureRfcommSocketToServiceRecord

        public BluetoothSocket createInsecureRfcommSocketToServiceRecord(UUID uuid)
                                                                  throws IOException
        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(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

        Parameters:
        uuid - service record uuid to lookup RFCOMM channel
        Returns:
        a RFCOMM BluetoothServerSocket ready for an outgoing connection
        Throws:
        IOException - on error, for example Bluetooth not available, or insufficient permissions
      • createInsecureRfcommSocket

        public BluetoothSocket createInsecureRfcommSocket(int port)
                                                   throws IOException
        Construct an insecure RFCOMM socket ready to start an outgoing connection. Call #connect on the returned #BluetoothSocket to begin the connection. The remote device will not be authenticated and communication on this socket will not be encrypted.

        Requires android.Manifest.permission#BLUETOOTH_ADMIN

        Parameters:
        port - remote port
        Returns:
        An RFCOMM BluetoothSocket
        Throws:
        IOException - On error, for example Bluetooth not available, or insufficient permissions.
      • createScoSocket

        public BluetoothSocket createScoSocket()
                                        throws IOException
        Construct a SCO socket ready to start an outgoing connection. Call #connect on the returned #BluetoothSocket to begin the connection.

        Requires android.Manifest.permission#BLUETOOTH_ADMIN

        Returns:
        a SCO BluetoothSocket
        Throws:
        IOException - on error, for example Bluetooth not available, or insufficient permissions.
      • convertPinToBytes

        public static byte[] convertPinToBytes(String pin)
        Check that a pin is valid and convert to byte array. Bluetooth pin's are 1 to 16 bytes of UTF-8 characters.
        Parameters:
        pin - pin as java String
        Returns:
        the pin code as a UTF-8 byte array, or null if it is an invalid Bluetooth pin.


Content

Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)

SQL

HTML

PHP

CSS

Java Script

MYSQL

JQUERY

VBS

REGEX

C

C++

C#

Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

License.
All information of this service is derived from the free sources and is provided solely in the form of quotations. This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 1124 / . Delta: 0.06291 с