STWBluetoothClassicManager

open class STWBluetoothClassicManager

STWBluetoothClassicManager

Description :

This class represent the API for all actions/event related to Classic Bluetooth This class offers several possible operations defined in the following list :

  • Start/Retry start Socket
  • Stop socket

This class offers also the possibility to listen for any events related to Classic Bluetooth.

Example of use

  • 
    To add the Support of SWhardware module to your project, include the following line in the dependencies block of your build.gradle file:
     
    
     dependencies {
          implementation project(':swhardware')
     }
    
  • 
            STWBluetoothClassicManager.getInstance().registerBluetoothSocketConnectionListenerCallback(getContext(),
            new BluetoothSocketConnectionListener() {
    
         public void getLastConnectedBluetoothDeviceAddress() {
    //Code...
         }
    
         public void onSocketConnected() {
    //Code...
         }
    
         public void onSocketClosed() {
    //Code...
         }
         });
    
  • 
            STWBluetoothClassicManager.getInstance().unregisterBluetoothSocketConnectionListener(BluetoothSocketConnectionListener);
    
  • 
            STWBluetoothClassicManager.getInstance().registerIClassicBluetoothEventCallback(getContext(), new IClassicBluetoothEventCallback() {
    
         public boolean shouldHandleActions() {
    //Code...
         }
    
         public void onButtonPressed() {
    //Code...
         }
    
         public void onButtonReleased() {
    //Code...
         }
         });
    
  • 
            STWBluetoothClassicManager.getInstance().unregisterClassicBluetoothEventCallback(IClassicBluetoothEventCallback);
    

Functions

Link copied to clipboard
open fun addBluetoothClassicPushActions(@NonNull action: String)
Called to add push action.
Link copied to clipboard
open fun addBluetoothClassicReleaseActions(@NonNull action: String)
Called to add release action.
Link copied to clipboard
open fun getBluetoothConnectedDevice(@NonNull context: Context): BluetoothDevice
Link copied to clipboard
open fun getCurrentBluetoothDeviceConnected(@NonNull context: Context, @Nullable address: String): BluetoothDevice
Called to return the connected bluetooth device.
Link copied to clipboard
open fun getInstance(): STWBluetoothClassicManager
Link copied to clipboard
open fun isSocketConnected(): Boolean
Called to check if Socket is connected.
open fun registerBluetoothSocketConnectionListenerCallback(@NonNull bluetoothSocketConnectionListener: BluetoothSocketConnectionListener)
Register the specified callback to be notified by Classic Bluetooth connection status.
Link copied to clipboard
open fun registerIClassicBluetoothEventCallback(@NonNull classicBluetoothEventCallback: IClassicBluetoothEventCallback)
Register the specified callback to be notified by Classic Bluetooth event.
Link copied to clipboard
open fun retryStartSocket(needRetry: Boolean, @NonNull context: Context): Boolean
Called when receiving a onSocketClosed callback.
Link copied to clipboard
open fun startSocket(@NonNull context: Context)
open fun startSocket(@NonNull context: Context, startSocketIfCustomAccessoryOnly: Boolean)
open fun startSocket(    @NonNull context: Context,     @Nullable bluetoothDeviceAddress: String,     startSocketIfCustomAccessoryOnly: Boolean)
START bluetooth socket do not open bluetooth socket since already connected to a BLE device avoid receiving multiple events from both classic bluetooth and BLE
open fun startSocketWithCustomAccessoryIfConnected(@NonNull context: Context)
Calle to retreive the connected accessory
Link copied to clipboard
open fun stopSocket()
open fun stopSocket(@NonNull address: String)
open fun stopSocket(@Nullable address: String, needForceStop: Boolean)
Called to sop socket.
open fun unregisterBluetoothSocketConnectionListener(@NonNull bluetoothSocketConnectionListener: BluetoothSocketConnectionListener)
Unregister the specified callback to not receive Classic bluetooth Connection status event again.
Link copied to clipboard
open fun unregisterClassicBluetoothEventCallback(@NonNull classicBluetoothEventCallback: IClassicBluetoothEventCallback)
Unregister the specified callback to not receive Classic Bluetooth event again.