Skip to content

Most visited

Recently visited

navigation

BluetoothProfileManager

BluetoothProfileManager

public final class BluetoothProfileManager
extends Object

java.lang.Object
   ↳ com.google.android.things.bluetooth.BluetoothProfileManager


Allows applications to enable/disable Bluetooth profiles on the system.

Usage of this API leads to a restart of the Bluetooth stack, and the changes take effect only after all the Bluetooth services have been restarted.

Usage:

 BluetoothProfileManager profileManager = new BluetoothProfileManager();

 List enabledProfiles = profileManager.getEnabledProfiles();
 String enabled = "";
 for (Integer profile : enabledProfiles) {
   enabled += ("" + profile + ", ");
 }
 Log.d(TAG, "Enabled Profiles - " + enabled);

 Log.d(TAG, "Enabling A2dp source mode.");
 List toEnable = Arrays.asList(BluetoothProfile.A2DP);
 List toDisable =
   Arrays.asList(BluetoothProfile.A2DP_SINK, BluetoothProfile.AVRCP_CONTROLLER);
 profileManager.enableAndDisableProfiles(toEnable, toDisable);
 

Certain configurations of profiles are invalid and will throw an IllegalArgumentException if used.

  • A2DP and A2DP_SINK profiles cannot be enabled together.
  • GATT profile cannot be disabled.

Summary

Public constructors

BluetoothProfileManager()

Construct BluetoothProfileManager

Public methods

void disableProfiles(List<Integer> toDisable)

Disables the specified Bluetooth profiles.

void enableAndDisableProfiles(List<Integer> toEnable, List<Integer> toDisable)

Enables/Disables the specified Bluetooth profiles.

void enableProfiles(List<Integer> toEnable)

Enables the specified Bluetooth profiles.

List<Integer> getEnabledProfiles()

Fetch the list of Bluetooth Profiles which are currently enabled in the system.

void setEnabledProfiles(List<Integer> profiles)

Sets the specified profiles to be enabled and disables all the other profiles.

Inherited methods

From class java.lang.Object

Public constructors

BluetoothProfileManager

BluetoothProfileManager ()

Construct BluetoothProfileManager

Throws
IllegalStateException if a connection cannot be established to the back-end service.

Public methods

disableProfiles

void disableProfiles (List<Integer> toDisable)

Disables the specified Bluetooth profiles.

This method disables the specified profiles from the existing set of enabled profiles. Note: Profiles not specified in the parameters will remain unaffected.

Parameters
toDisable List: List of BluetoothProfile to disable.
Throws
IllegalStateException when the connection to the server has died.
IllegalArgumentException when profiles configuration is invalid.

enableAndDisableProfiles

void enableAndDisableProfiles (List<Integer> toEnable, 
                List<Integer> toDisable)

Enables/Disables the specified Bluetooth profiles.

This method enables/disables the specified profiles from the existing set of already enabled profiles. Note: Profiles not specified in the parameters will remain unaffected.

Parameters
toEnable List: List of BluetoothProfile to enable.
toDisable List: List of BluetoothProfile to disable.
Throws
IllegalStateException when the connection to the server has died.
IllegalArgumentException when profiles configuration is invalid.

enableProfiles

void enableProfiles (List<Integer> toEnable)

Enables the specified Bluetooth profiles.

This method enables the specified profiles in addition to the already enabled profiles. Note: Profiles not specified in the parameters will remain unaffected.

Parameters
toEnable List: List of BluetoothProfile to enable.
Throws
IllegalStateException when the connection to the server has died.
IllegalArgumentException when profiles configuration is invalid.

getEnabledProfiles

List<Integer> getEnabledProfiles ()

Fetch the list of Bluetooth Profiles which are currently enabled in the system.

It's important to note that this method currently only returns profiles not disabled by system settings. For Android Things, we plan to control enabled/disabled profiles using the settings mask so this should always be correct.

Returns
List<Integer>
Throws
IllegalStateException when the connection to the server has died.

setEnabledProfiles

void setEnabledProfiles (List<Integer> profiles)

Sets the specified profiles to be enabled and disables all the other profiles. Note: This method will remove all previous state and only enable the specified profiles.

Parameters
profiles List: List of BluetoothProfile to be enabled.
Throws
IllegalStateException when the connection to the server has died.
IllegalArgumentException when profiles configuration is invalid.
This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Follow Google Developers on WeChat

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience. (Dec 2017 Android Platform & Tools Survey)