Skip to content

Most visited

Recently visited

navigation

BluetoothProfileManager

BluetoothProfileManager

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

 public class SwitchProfileActivity extends Activity implements ServiceListener {
      private static final String TAG = SwitchProfileActivity.class.getName();

      private BluetoothProfileManager mProfileManager;

      @Override
      protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mProfileManager = new BluetoothProfileManager(this, this);
      }

      @Override
      public void onServiceConnected(BluetoothProfileManager bluetoothProfileManager) {
        List enabledProfiles = mProfileManager.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);
        mProfileManager.enableAndDisableProfiles(toEnable, toDisable);
      }

      @Override
      public void onServiceDisconnected() {
      }
  }
 

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

Summary

Nested classes

interface BluetoothProfileManager.ServiceListener

Simple callback interface used to notify clients when we connect to IBluetoothProfileManager service. 

Public constructors

BluetoothProfileManager(Context context, BluetoothProfileManager.ServiceListener serviceListener)

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 (Context context, 
                BluetoothProfileManager.ServiceListener serviceListener)

Parameters
context Context: caller Context.
serviceListener BluetoothProfileManager.ServiceListener: Callback to invoke once service has been connected.

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!

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 one-minute survey?
Help us improve Android tools and documentation.