IT. Expert System.

Android Reference

BluetoothAdapter


android.bluetooth

Class BluetoothAdapter

    • 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(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR)

        See Also:
        Constant Field Values
      • ACTION_STATE_CHANGED

        public static final String ACTION_STATE_CHANGED
        Broadcast Action: The state of the local Bluetooth adapter has been changed.

        For example, Bluetooth has been turned on or off.

        Always contains the extra fields EXTRA_STATE and EXTRA_PREVIOUS_STATE containing the new and old states respectively.

        Requires android.Manifest.permission#BLUETOOTH to receive.

        See Also:
        Constant Field Values
      • STATE_OFF

        public static final int STATE_OFF
        Indicates the local Bluetooth adapter is off.
        See Also:
        Constant Field Values
      • STATE_TURNING_ON

        public static final int STATE_TURNING_ON
        Indicates the local Bluetooth adapter is turning on. However local clients should wait for STATE_ON before attempting to use the adapter.
        See Also:
        Constant Field Values
      • STATE_ON

        public static final int STATE_ON
        Indicates the local Bluetooth adapter is on, and ready for use.
        See Also:
        Constant Field Values
      • STATE_TURNING_OFF

        public static final int STATE_TURNING_OFF
        Indicates the local Bluetooth adapter is turning off. Local clients should immediately attempt graceful disconnection of any remote links.
        See Also:
        Constant Field Values
      • ACTION_REQUEST_DISCOVERABLE

        public static final String ACTION_REQUEST_DISCOVERABLE
        Activity Action: Show a system activity that requests discoverable mode. This activity will also request the user to turn on Bluetooth if it is not currently enabled.

        Discoverable mode is equivalent to SCAN_MODE_CONNECTABLE_DISCOVERABLE. It allows remote devices to see this Bluetooth adapter when they perform a discovery.

        For privacy, Android is not discoverable by default.

        The sender of this Intent can optionally use extra field EXTRA_DISCOVERABLE_DURATION to request the duration of discoverability. Currently the default duration is 120 seconds, and maximum duration is capped at 300 seconds for each request.

        Notification of the result of this activity is posted using the Activity.onActivityResult(int, int, android.content.Intent) callback. The resultCode will be the duration (in seconds) of discoverability or Activity.RESULT_CANCELED if the user rejected discoverability or an error has occurred.

        Applications can also listen for ACTION_SCAN_MODE_CHANGED for global notification whenever the scan mode changes. For example, an application can be notified when the device has ended discoverability.

        Requires android.Manifest.permission#BLUETOOTH

        See Also:
        Constant Field Values
      • EXTRA_DISCOVERABLE_DURATION

        public static final String EXTRA_DISCOVERABLE_DURATION
        Used as an optional int extra field in ACTION_REQUEST_DISCOVERABLE intents to request a specific duration for discoverability in seconds. The current default is 120 seconds, and requests over 300 seconds will be capped. These values could change.
        See Also:
        Constant Field Values
      • ACTION_REQUEST_ENABLE

        public static final String ACTION_REQUEST_ENABLE
        Activity Action: Show a system activity that allows the user to turn on Bluetooth.

        This system activity will return once Bluetooth has completed turning on, or the user has decided not to turn Bluetooth on.

        Notification of the result of this activity is posted using the Activity.onActivityResult(int, int, android.content.Intent) callback. The resultCode will be Activity.RESULT_OK if Bluetooth has been turned on or Activity.RESULT_CANCELED if the user has rejected the request or an error has occurred.

        Applications can also listen for ACTION_STATE_CHANGED for global notification whenever Bluetooth is turned on or off.

        Requires android.Manifest.permission#BLUETOOTH

        See Also:
        Constant Field Values
      • ACTION_SCAN_MODE_CHANGED

        public static final String ACTION_SCAN_MODE_CHANGED
        Broadcast Action: Indicates the Bluetooth scan mode of the local Adapter has changed.

        Always contains the extra fields EXTRA_SCAN_MODE and EXTRA_PREVIOUS_SCAN_MODE containing the new and old scan modes respectively.

        Requires android.Manifest.permission#BLUETOOTH

        See Also:
        Constant Field Values
      • SCAN_MODE_NONE

        public static final int SCAN_MODE_NONE
        Indicates that both inquiry scan and page scan are disabled on the local Bluetooth adapter. Therefore this device is neither discoverable nor connectable from remote Bluetooth devices.
        See Also:
        Constant Field Values
      • SCAN_MODE_CONNECTABLE

        public static final int SCAN_MODE_CONNECTABLE
        Indicates that inquiry scan is disabled, but page scan is enabled on the local Bluetooth adapter. Therefore this device is not discoverable from remote Bluetooth devices, but is connectable from remote devices that have previously discovered this device.
        See Also:
        Constant Field Values
      • SCAN_MODE_CONNECTABLE_DISCOVERABLE

        public static final int SCAN_MODE_CONNECTABLE_DISCOVERABLE
        Indicates that both inquiry scan and page scan are enabled on the local Bluetooth adapter. Therefore this device is both discoverable and connectable from remote Bluetooth devices.
        See Also:
        Constant Field Values
      • ACTION_DISCOVERY_STARTED

        public static final String ACTION_DISCOVERY_STARTED
        Broadcast Action: The local Bluetooth adapter has started the remote device discovery process.

        This usually involves an inquiry scan of about 12 seconds, followed by a page scan of each new device to retrieve its Bluetooth name.

        Register for BluetoothDevice.ACTION_FOUND to be notified as remote Bluetooth devices are found.

        Device discovery is a heavyweight procedure. New connections to remote Bluetooth devices should not be attempted while discovery is in progress, and existing connections will experience limited bandwidth and high latency. Use cancelDiscovery() to cancel an ongoing discovery.

        Requires android.Manifest.permission#BLUETOOTH to receive.

        See Also:
        Constant Field Values
      • ACTION_DISCOVERY_FINISHED

        public static final String ACTION_DISCOVERY_FINISHED
        Broadcast Action: The local Bluetooth adapter has finished the device discovery process.

        Requires android.Manifest.permission#BLUETOOTH to receive.

        See Also:
        Constant Field Values
      • ACTION_LOCAL_NAME_CHANGED

        public static final String ACTION_LOCAL_NAME_CHANGED
        Broadcast Action: The local Bluetooth adapter has changed its friendly Bluetooth name.

        This name is visible to remote Bluetooth devices.

        Always contains the extra field EXTRA_LOCAL_NAME containing the name.

        Requires android.Manifest.permission#BLUETOOTH to receive.

        See Also:
        Constant Field Values
      • ACTION_CONNECTION_STATE_CHANGED

        public static final String ACTION_CONNECTION_STATE_CHANGED
        Intent used to broadcast the change in connection state of the local Bluetooth adapter to a profile of the remote device. When the adapter is not connected to any profiles of any remote devices and it attempts a connection to a profile this intent will sent. Once connected, this intent will not be sent for any more connection attempts to any profiles of any remote device. When the adapter disconnects from the last profile its connected to of any remote device, this intent will be sent.

        This intent is useful for applications that are only concerned about whether the local adapter is connected to any profile of any device and are not really concerned about which profile. For example, an application which displays an icon to display whether Bluetooth is connected or not can use this intent.

        This intent will have 3 extras: EXTRA_CONNECTION_STATE - The current connection state. EXTRA_PREVIOUS_CONNECTION_STATE- The previous connection state. BluetoothDevice.EXTRA_DEVICE - The remote device. EXTRA_CONNECTION_STATE or EXTRA_PREVIOUS_CONNECTION_STATE can be any of STATE_DISCONNECTED, STATE_CONNECTING, STATE_CONNECTED, STATE_DISCONNECTING.

        Requires android.Manifest.permission#BLUETOOTH to receive.

        See Also:
        Constant Field Values
      • STATE_DISCONNECTED

        public static final int STATE_DISCONNECTED
        The profile is in disconnected state
        See Also:
        Constant Field Values
      • STATE_CONNECTING

        public static final int STATE_CONNECTING
        The profile is in connecting state
        See Also:
        Constant Field Values
      • STATE_CONNECTED

        public static final int STATE_CONNECTED
        The profile is in connected state
        See Also:
        Constant Field Values
      • STATE_DISCONNECTING

        public static final int STATE_DISCONNECTING
        The profile is in disconnecting state
        See Also:
        Constant Field Values
    • Method Detail

      • getDefaultAdapter

        public static BluetoothAdapter getDefaultAdapter()
        Get a handle to the default local Bluetooth adapter.

        Currently Android only supports one Bluetooth adapter, but the API could be extended to support more. This will always return the default adapter.

        Returns:
        the default local adapter, or null if Bluetooth is not supported on this hardware platform
      • getRemoteDevice

        public BluetoothDevice getRemoteDevice(byte[] address)
        Get a BluetoothDevice object for the given Bluetooth hardware address.

        Valid Bluetooth hardware addresses must be 6 bytes. This method expects the address in network byte order (MSB first).

        A BluetoothDevice will always be returned for a valid hardware address, even if this adapter has never seen that device.

        Parameters:
        address - Bluetooth MAC address (6 bytes)
        Throws:
        IllegalArgumentException - if address is invalid
      • isEnabled

        public boolean isEnabled()
        Return true if Bluetooth is currently enabled and ready for use.

        Equivalent to: getBluetoothState() == STATE_ON

        Requires android.Manifest.permission#BLUETOOTH

        Returns:
        true if the local adapter is turned on
      • getState

        public int getState()
        Get the current state of the local Bluetooth adapter.

        Possible return values are STATE_OFF, STATE_TURNING_ON, STATE_ON, STATE_TURNING_OFF.

        Requires android.Manifest.permission#BLUETOOTH

        Returns:
        current state of Bluetooth adapter
      • enable

        public boolean enable()
        Turn on the local Bluetooth adapter—do not use without explicit user action to turn on Bluetooth.

        This powers on the underlying Bluetooth hardware, and starts all Bluetooth system services.

        Bluetooth should never be enabled without direct user consent. If you want to turn on Bluetooth in order to create a wireless connection, you should use the ACTION_REQUEST_ENABLE Intent, which will raise a dialog that requests user permission to turn on Bluetooth. The enable() method is provided only for applications that include a user interface for changing system settings, such as a "power manager" app.

        This is an asynchronous call: it will return immediately, and clients should listen for ACTION_STATE_CHANGED to be notified of subsequent adapter state changes. If this call returns true, then the adapter state will immediately transition from STATE_OFF to STATE_TURNING_ON, and some time later transition to either STATE_OFF or STATE_ON. If this call returns false then there was an immediate problem that will prevent the adapter from being turned on - such as Airplane mode, or the adapter is already turned on.

        Requires the android.Manifest.permission#BLUETOOTH_ADMIN permission

        Returns:
        true to indicate adapter startup has begun, or false on immediate error
      • disable

        public boolean disable()
        Turn off the local Bluetooth adapter—do not use without explicit user action to turn off Bluetooth.

        This gracefully shuts down all Bluetooth connections, stops Bluetooth system services, and powers down the underlying Bluetooth hardware.

        Bluetooth should never be disabled without direct user consent. The disable() method is provided only for applications that include a user interface for changing system settings, such as a "power manager" app.

        This is an asynchronous call: it will return immediately, and clients should listen for ACTION_STATE_CHANGED to be notified of subsequent adapter state changes. If this call returns true, then the adapter state will immediately transition from STATE_ON to STATE_TURNING_OFF, and some time later transition to either STATE_OFF or STATE_ON. If this call returns false then there was an immediate problem that will prevent the adapter from being turned off - such as the adapter already being turned off.

        Requires the android.Manifest.permission#BLUETOOTH_ADMIN permission

        Returns:
        true to indicate adapter shutdown has begun, or false on immediate error
      • disable

        public boolean disable(boolean persist)
        Turn off the local Bluetooth adapter and don't persist the setting.

        Requires the android.Manifest.permission#BLUETOOTH_ADMIN permission

        Returns:
        true to indicate adapter shutdown has begun, or false on immediate error
      • getAddress

        public String getAddress()
        Returns the hardware address of the local Bluetooth adapter.

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

        Requires android.Manifest.permission#BLUETOOTH

        Returns:
        Bluetooth hardware address as string
      • getName

        public String getName()
        Get the friendly Bluetooth name of the local Bluetooth adapter.

        This name is visible to remote Bluetooth devices.

        Requires android.Manifest.permission#BLUETOOTH

        Returns:
        the Bluetooth name, or null on error
      • getUuids

        public ParcelUuid[] getUuids()
        Get the UUIDs supported by the local Bluetooth adapter.

        Requires android.Manifest.permission#BLUETOOTH

        Returns:
        the UUIDs supported by the local Bluetooth Adapter.
      • setName

        public boolean setName(String name)
        Set the friendly Bluetooth name of the local Bluetooth adapter.

        This name is visible to remote Bluetooth devices.

        Valid Bluetooth names are a maximum of 248 bytes using UTF-8 encoding, although many remote devices can only display the first 40 characters, and some may be limited to just 20.

        If Bluetooth state is not STATE_ON, this API will return false. After turning on Bluetooth, wait for ACTION_STATE_CHANGED with STATE_ON to get the updated value.

        Requires android.Manifest.permission#BLUETOOTH_ADMIN

        Parameters:
        name - a valid Bluetooth name
        Returns:
        true if the name was set, false otherwise
      • setScanMode

        public boolean setScanMode(int mode,
                          int duration)
        Set the Bluetooth scan mode of the local Bluetooth adapter.

        The Bluetooth scan mode determines if the local adapter is connectable and/or discoverable from remote Bluetooth devices.

        For privacy reasons, discoverable mode is automatically turned off after duration seconds. For example, 120 seconds should be enough for a remote device to initiate and complete its discovery process.

        Valid scan mode values are: SCAN_MODE_NONE, SCAN_MODE_CONNECTABLE, SCAN_MODE_CONNECTABLE_DISCOVERABLE.

        If Bluetooth state is not STATE_ON, this API will return false. After turning on Bluetooth, wait for ACTION_STATE_CHANGED with STATE_ON to get the updated value.

        Requires android.Manifest.permission#WRITE_SECURE_SETTINGS

        Applications cannot set the scan mode. They should use startActivityForResult( BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE}) instead.

        Parameters:
        mode - valid scan mode
        duration - time in seconds to apply scan mode, only used for SCAN_MODE_CONNECTABLE_DISCOVERABLE
        Returns:
        true if the scan mode was set, false otherwise
      • setScanMode

        public boolean setScanMode(int mode)
      • getDiscoverableTimeout

        public int getDiscoverableTimeout()
      • setDiscoverableTimeout

        public void setDiscoverableTimeout(int timeout)
      • startDiscovery

        public boolean startDiscovery()
        Start the remote device discovery process.

        The discovery process usually involves an inquiry scan of about 12 seconds, followed by a page scan of each new device to retrieve its Bluetooth name.

        This is an asynchronous call, it will return immediately. Register for ACTION_DISCOVERY_STARTED and ACTION_DISCOVERY_FINISHED intents to determine exactly when the discovery starts and completes. Register for BluetoothDevice.ACTION_FOUND to be notified as remote Bluetooth devices are found.

        Device discovery is a heavyweight procedure. New connections to remote Bluetooth devices should not be attempted while discovery is in progress, and existing connections will experience limited bandwidth and high latency. Use cancelDiscovery() to cancel an ongoing discovery. Discovery is not managed by the Activity, but is run as a system service, so an application should always call cancelDiscovery() even if it did not directly request a discovery, just to be sure.

        Device discovery will only find remote devices that are currently discoverable (inquiry scan enabled). Many Bluetooth devices are not discoverable by default, and need to be entered into a special mode.

        If Bluetooth state is not STATE_ON, this API will return false. After turning on Bluetooth, wait for ACTION_STATE_CHANGED with STATE_ON to get the updated value.

        Requires android.Manifest.permission#BLUETOOTH_ADMIN.

        Returns:
        true on success, false on error
      • cancelDiscovery

        public boolean cancelDiscovery()
        Cancel the current device discovery process.

        Requires android.Manifest.permission#BLUETOOTH_ADMIN.

        Because discovery is a heavyweight procedure for the Bluetooth adapter, this method should always be called before attempting to connect to a remote device with BluetoothSocket.connect(). Discovery is not managed by the Activity, but is run as a system service, so an application should always call cancel discovery even if it did not directly request a discovery, just to be sure.

        If Bluetooth state is not STATE_ON, this API will return false. After turning on Bluetooth, wait for ACTION_STATE_CHANGED with STATE_ON to get the updated value.

        Returns:
        true on success, false on error
      • isDiscovering

        public boolean isDiscovering()
        Return true if the local Bluetooth adapter is currently in the device discovery process.

        Device discovery is a heavyweight procedure. New connections to remote Bluetooth devices should not be attempted while discovery is in progress, and existing connections will experience limited bandwidth and high latency. Use cancelDiscovery() to cancel an ongoing discovery.

        Applications can also register for ACTION_DISCOVERY_STARTED or ACTION_DISCOVERY_FINISHED to be notified when discovery starts or completes.

        If Bluetooth state is not STATE_ON, this API will return false. After turning on Bluetooth, wait for ACTION_STATE_CHANGED with STATE_ON to get the updated value.

        Requires android.Manifest.permission#BLUETOOTH.

        Returns:
        true if discovering
      • getBondedDevices

        public Set<BluetoothDevice> getBondedDevices()
        Return the set of BluetoothDevice objects that are bonded (paired) to the local adapter.

        If Bluetooth state is not STATE_ON, this API will return an empty set. After turning on Bluetooth, wait for ACTION_STATE_CHANGED with STATE_ON to get the updated value.

        Requires android.Manifest.permission#BLUETOOTH.

        Returns:
        unmodifiable set of BluetoothDevice, or null on error
      • listenUsingRfcommOn

        public BluetoothServerSocket listenUsingRfcommOn(int channel)
                                                  throws IOException
        Create a listening, secure RFCOMM Bluetooth socket.

        A remote device connecting to this socket will be authenticated and communication on this socket will be encrypted.

        Use BluetoothServerSocket.accept() to retrieve incoming connections from a listening BluetoothServerSocket.

        Valid RFCOMM channels are in range 1 to 30.

        Requires android.Manifest.permission#BLUETOOTH_ADMIN

        Parameters:
        channel - RFCOMM channel to listen on
        Returns:
        a listening RFCOMM BluetoothServerSocket
        Throws:
        IOException - on error, for example Bluetooth not available, or insufficient permissions, or channel in use.
      • listenUsingRfcommWithServiceRecord

        public BluetoothServerSocket listenUsingRfcommWithServiceRecord(String name,
                                                               UUID uuid)
                                                                 throws IOException
        Create a listening, secure RFCOMM Bluetooth socket with Service Record.

        A remote device connecting to this socket will be authenticated and communication on this socket will be encrypted.

        Use BluetoothServerSocket.accept() to retrieve incoming connections from a listening BluetoothServerSocket.

        The system will assign an unused RFCOMM channel to listen on.

        The system will also register a Service Discovery Protocol (SDP) record with the local SDP server containing the specified UUID, service name, and auto-assigned channel. Remote Bluetooth devices can use the same UUID to query our SDP server and discover which channel to connect to. This SDP record will be removed when this socket is closed, or if this application closes unexpectedly.

        Use BluetoothDevice.createRfcommSocketToServiceRecord(java.util.UUID) to connect to this socket from another device using the same UUID.

        Requires android.Manifest.permission#BLUETOOTH

        Parameters:
        name - service name for SDP record
        uuid - uuid for SDP record
        Returns:
        a listening RFCOMM BluetoothServerSocket
        Throws:
        IOException - on error, for example Bluetooth not available, or insufficient permissions, or channel in use.
      • listenUsingInsecureRfcommWithServiceRecord

        public BluetoothServerSocket listenUsingInsecureRfcommWithServiceRecord(String name,
                                                                       UUID uuid)
                                                                         throws IOException
        Create a listening, insecure RFCOMM Bluetooth socket with Service Record.

        The link key is not required to be authenticated, i.e the communication may be vulnerable to Man In the Middle attacks. For Bluetooth 2.1 devices, the link will be encrypted, as encryption is mandartory. For legacy devices (pre Bluetooth 2.1 devices) the link will not be encrypted. Use listenUsingRfcommWithServiceRecord(java.lang.String, java.util.UUID), if an encrypted and authenticated communication channel is desired.

        Use BluetoothServerSocket.accept() to retrieve incoming connections from a listening BluetoothServerSocket.

        The system will assign an unused RFCOMM channel to listen on.

        The system will also register a Service Discovery Protocol (SDP) record with the local SDP server containing the specified UUID, service name, and auto-assigned channel. Remote Bluetooth devices can use the same UUID to query our SDP server and discover which channel to connect to. This SDP record will be removed when this socket is closed, or if this application closes unexpectedly.

        Use BluetoothDevice.createRfcommSocketToServiceRecord(java.util.UUID) to connect to this socket from another device using the same UUID.

        Requires android.Manifest.permission#BLUETOOTH

        Parameters:
        name - service name for SDP record
        uuid - uuid for SDP record
        Returns:
        a listening RFCOMM BluetoothServerSocket
        Throws:
        IOException - on error, for example Bluetooth not available, or insufficient permissions, or channel in use.
      • listenUsingEncryptedRfcommWithServiceRecord

        public BluetoothServerSocket listenUsingEncryptedRfcommWithServiceRecord(String name,
                                                                        UUID uuid)
                                                                          throws IOException
        Create a listening, encrypted, RFCOMM Bluetooth socket with Service Record.

        The link will be encrypted, but the link key is not required to be authenticated i.e the communication is vulnerable to Man In the Middle attacks. Use listenUsingRfcommWithServiceRecord(java.lang.String, java.util.UUID), to ensure an authenticated link key.

        Use this socket if authentication of link key is not possible. 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 and this socket can be used. Use listenUsingInsecureRfcommWithServiceRecord(java.lang.String, java.util.UUID), if encryption is not required. For Bluetooth 2.1 devices, the link will be encrypted, as encryption is mandartory. For more details, refer to the Security Model section 5.2 (vol 3) of Bluetooth Core Specification version 2.1 + EDR.

        Use BluetoothServerSocket.accept() to retrieve incoming connections from a listening BluetoothServerSocket.

        The system will assign an unused RFCOMM channel to listen on.

        The system will also register a Service Discovery Protocol (SDP) record with the local SDP server containing the specified UUID, service name, and auto-assigned channel. Remote Bluetooth devices can use the same UUID to query our SDP server and discover which channel to connect to. This SDP record will be removed when this socket is closed, or if this application closes unexpectedly.

        Use BluetoothDevice.createRfcommSocketToServiceRecord(java.util.UUID) to connect to this socket from another device using the same UUID.

        Requires android.Manifest.permission#BLUETOOTH

        Parameters:
        name - service name for SDP record
        uuid - uuid for SDP record
        Returns:
        a listening RFCOMM BluetoothServerSocket
        Throws:
        IOException - on error, for example Bluetooth not available, or insufficient permissions, or channel in use.
      • listenUsingInsecureRfcommOn

        public BluetoothServerSocket listenUsingInsecureRfcommOn(int port)
                                                          throws IOException
        Construct an unencrypted, unauthenticated, RFCOMM server socket. Call #accept to retrieve connections to this socket.
        Returns:
        An RFCOMM BluetoothServerSocket
        Throws:
        IOException - On error, for example Bluetooth not available, or insufficient permissions.
      • listenUsingEncryptedRfcommOn

        public BluetoothServerSocket listenUsingEncryptedRfcommOn(int port)
                                                           throws IOException
        Construct an encrypted, RFCOMM server socket. Call #accept to retrieve connections to this socket.
        Returns:
        An RFCOMM BluetoothServerSocket
        Throws:
        IOException - On error, for example Bluetooth not available, or insufficient permissions.
      • listenUsingScoOn

        public static BluetoothServerSocket listenUsingScoOn()
                                                      throws IOException
        Construct a SCO server socket. Call #accept to retrieve connections to this socket.
        Returns:
        A SCO BluetoothServerSocket
        Throws:
        IOException - On error, for example Bluetooth not available, or insufficient permissions.
      • readOutOfBandData

        public Pair<byte[],byte[]> readOutOfBandData()
        Read the local Out of Band Pairing Data

        Requires android.Manifest.permission#BLUETOOTH

        Returns:
        Pair of Hash and Randomizer
      • enableNoAutoConnect

        public boolean enableNoAutoConnect()
        Enable the Bluetooth Adapter, but don't auto-connect devices and don't persist state. Only for use by system applications.
      • changeApplicationBluetoothState

        public boolean changeApplicationBluetoothState(boolean on,
                                              BluetoothAdapter.BluetoothStateChangeCallback callback)
        Enable control of the Bluetooth Adapter for a single application.

        Some applications need to use Bluetooth for short periods of time to transfer data but don't want all the associated implications like automatic connection to headsets etc.

        Multiple applications can call this. This is reference counted and Bluetooth disabled only when no one else is using it. There will be no UI shown to the user while bluetooth is being enabled. Any user action will override this call. For example, if user wants Bluetooth on and the last user of this API wanted to disable Bluetooth, Bluetooth will not be turned off.

        This API is only meant to be used by internal applications. Third party applications but use enable() and disable() APIs.

        If this API returns true, it means the callback will be called. The callback will be called with the current state of Bluetooth. If the state is not what was requested, an internal error would be the reason. If Bluetooth is already on and if this function is called to turn it on, the api will return true and a callback will be called.

        Requires android.Manifest.permission#BLUETOOTH

        Parameters:
        on - True for on, false for off.
        callback - The callback to notify changes to the state.
      • finalize

        protected void finalize()
                         throws Throwable
        Description copied from class: Object
        Invoked when the garbage collector has detected that this instance is no longer reachable. The default implementation does nothing, but this method can be overridden to free resources.

        Note that objects that override finalize are significantly more expensive than objects that don't. Finalizers may be run a long time after the object is no longer reachable, depending on memory pressure, so it's a bad idea to rely on them for cleanup. Note also that finalizers are run on a single VM-wide finalizer thread, so doing blocking work in a finalizer is a bad idea. A finalizer is usually only necessary for a class that has a native peer and needs to call a native method to destroy that peer. Even then, it's better to provide an explicit close method (and implement Closeable), and insist that callers manually dispose of instances. This works well for something like files, but less well for something like a BigInteger where typical calling code would have to deal with lots of temporaries. Unfortunately, code that creates lots of temporaries is the worst kind of code from the point of view of the single finalizer thread.

        If you must use finalizers, consider at least providing your own ReferenceQueue and having your own thread process that queue.

        Unlike constructors, finalizers are not automatically chained. You are responsible for calling super.finalize() yourself.

        Uncaught exceptions thrown by finalizers are ignored and do not terminate the finalizer thread. See Effective Java Item 7, "Avoid finalizers" for more.

        Overrides:
        finalize in class Object
        Throws:
        Throwable
      • checkBluetoothAddress

        public static boolean checkBluetoothAddress(String address)
        Validate a String Bluetooth address, such as "00:43:A8:23:10:F0"

        Alphabetic characters must be uppercase to be valid.

        Parameters:
        address - Bluetooth address as string
        Returns:
        true if the address is valid, false otherwise


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: 1435 / . Delta: 0.08534 с