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 triggers a restart of the Bluetooth stack, and the changes take effect only after all the Bluetooth services have been restarted.
Usage:
BluetoothProfileManager profileManager = BluetoothProfileManager.getInstance(); ListenabledProfiles = 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 behave differently.
A2DPandA2DP_SINKprofiles cannot be enabled together. Doing so will throw anIllegalArgumentException.GATTprofile cannot be disabled. It is active if Bluetooth is ON.GATT_SERVERprofile cannot be controlled using these APIs. Using them will have no effect. It is always active in conjunction withGATT.
Summary
Public methods | |
|---|---|
        
        
        
        
        
        boolean
     | 
  
    
      
      disableProfiles(List<Integer> toDisable)
      
      
        Disables the specified Bluetooth profiles.  | 
  
        
        
        
        
        
        boolean
     | 
  
    
      
      enableAndDisableProfiles(List<Integer> toEnable, List<Integer> toDisable)
      
      
        Enables/Disables the specified Bluetooth profiles.  | 
  
        
        
        
        
        
        boolean
     | 
  
    
      
      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.  | 
  
        
        
        static
        
        
        BluetoothProfileManager
     | 
  
    
      
      getInstance()
      
      
        Fetch an instance of   | 
  
        
        
        
        
        
        boolean
     | 
  
    
      
      setEnabledProfiles(List<Integer> profiles)
      
      
        Sets the specified profiles to be enabled and disables all the other profiles.  | 
  
Inherited methods | |
|---|---|
  
    
  
    java.lang.Object
  
 | |
Public methods
disableProfiles
boolean disableProfiles (List<Integer> toDisable)
Disables the specified Bluetooth profiles.
This method disables the specified profiles from the existing set of enabled profiles. Profiles not specified in the parameters will remain unaffected.
| Parameters | |
|---|---|
toDisable | 
        
          List: List of BluetoothProfile to disable. | 
      
| Returns | |
|---|---|
boolean | 
        False if unable to disable profile or if profile is already disabled. True otherwise. | 
| Throws | |
|---|---|
IllegalStateException | 
          when the connection to the server has died. | 
IllegalArgumentException | 
          when profiles configuration is invalid. | 
enableAndDisableProfiles
boolean enableAndDisableProfiles (List<Integer> toEnable, List<Integer> toDisable)
Enables/Disables the specified Bluetooth profiles.
This method enables/disables the specified profiles on the device. Profiles not specified in the parameters will remain unaffected.
| Parameters | |
|---|---|
toEnable | 
        
          List: List of BluetoothProfile to enable. | 
      
toDisable | 
        
          List: List of BluetoothProfile to disable. | 
      
| Returns | |
|---|---|
boolean | 
        False if unable to modify profile state or if no change is needed. True otherwise. | 
| Throws | |
|---|---|
IllegalStateException | 
          when the connection to the server has died. | 
IllegalArgumentException | 
          when profiles configuration is invalid. | 
enableProfiles
boolean enableProfiles (List<Integer> toEnable)
Enables the specified Bluetooth profiles.
This method enables the specified profiles in addition to the already enabled profiles. Profiles not specified in the parameters will remain unaffected.
| Parameters | |
|---|---|
toEnable | 
        
          List: List of BluetoothProfile to enable. | 
      
| Returns | |
|---|---|
boolean | 
        False if unable to enable profile or if profile is already enabled. True otherwise. | 
| 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.
| Returns | |
|---|---|
List<Integer> | 
        |
| Throws | |
|---|---|
IllegalStateException | 
          when the connection to the server has died. | 
getInstance
BluetoothProfileManager getInstance ()
Fetch an instance of BluetoothProfileManager
| Returns | |
|---|---|
BluetoothProfileManager | 
        |
| Throws | |
|---|---|
IllegalStateException | 
          if a connection cannot be established to the back-end service. | 
setEnabledProfiles
boolean setEnabledProfiles (List<Integer> profiles)
Sets the specified profiles to be enabled and disables all the other profiles.
This method will remove all previous state and only enable the specified profiles.
| Parameters | |
|---|---|
profiles | 
        
          List: List of BluetoothProfile to be enabled. | 
      
| Returns | |
|---|---|
boolean | 
        |
| Throws | |
|---|---|
IllegalStateException | 
          when the connection to the server has died. | 
IllegalArgumentException | 
          when profiles configuration is invalid. |