STWBluetooth Classic Manager
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') }Content copied to clipboardContent copied to clipboardSTWBluetoothClassicManager.getInstance().registerBluetoothSocketConnectionListenerCallback(getContext(), new BluetoothSocketConnectionListener() { public void getLastConnectedBluetoothDeviceAddress() { //Code... } public void onSocketConnected() { //Code... } public void onSocketClosed() { //Code... } });Content copied to clipboardContent copied to clipboardSTWBluetoothClassicManager.getInstance().unregisterBluetoothSocketConnectionListener(BluetoothSocketConnectionListener);Content copied to clipboardContent copied to clipboardSTWBluetoothClassicManager.getInstance().registerIClassicBluetoothEventCallback(getContext(), new IClassicBluetoothEventCallback() { public boolean shouldHandleActions() { //Code... } public void onButtonPressed() { //Code... } public void onButtonReleased() { //Code... } });Content copied to clipboardContent copied to clipboardSTWBluetoothClassicManager.getInstance().unregisterClassicBluetoothEventCallback(IClassicBluetoothEventCallback);Content copied to clipboardContent copied to clipboard
Functions
Link copied to clipboard
Called to add push action.
Link copied to clipboard
Called to add release action.
Link copied to clipboard
open fun getBluetoothConnectedDevice(@NonNull context: Context): BluetoothDevice
Content copied to clipboard
Link copied to clipboard
open fun getCurrentBluetoothDeviceConnected(@NonNull context: Context, @Nullable address: String): BluetoothDevice
Content copied to clipboard
Called to return the connected bluetooth device.
Link copied to clipboard
Link copied to clipboard
Called to check if Socket is connected.
Link copied to clipboard
open fun registerBluetoothSocketConnectionListenerCallback(@NonNull bluetoothSocketConnectionListener: BluetoothSocketConnectionListener)
Content copied to clipboard
Register the specified callback to be notified by Classic Bluetooth connection status.
Link copied to clipboard
open fun registerIClassicBluetoothEventCallback(@NonNull classicBluetoothEventCallback: IClassicBluetoothEventCallback)
Content copied to clipboard
Register the specified callback to be notified by Classic Bluetooth event.
Link copied to clipboard
open fun retryStartSocket(needRetry: Boolean, @NonNull context: Context): Boolean
Content copied to clipboard
Called when receiving a onSocketClosed callback.
Link copied to clipboard
open fun startSocket(@NonNull context: Context, startSocketIfCustomAccessoryOnly: Boolean)
Content copied to clipboard
open fun startSocket( @NonNull context: Context, @Nullable bluetoothDeviceAddress: String, startSocketIfCustomAccessoryOnly: Boolean)
Content copied to clipboard
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
Link copied to clipboard
open fun startSocketWithCustomAccessoryIfConnected(@NonNull context: Context)
Content copied to clipboard
Calle to retreive the connected accessory
Link copied to clipboard
Called to sop socket.
Link copied to clipboard
open fun unregisterBluetoothSocketConnectionListener(@NonNull bluetoothSocketConnectionListener: BluetoothSocketConnectionListener)
Content copied to clipboard
Unregister the specified callback to not receive Classic bluetooth Connection status event again.
Link copied to clipboard
open fun unregisterClassicBluetoothEventCallback(@NonNull classicBluetoothEventCallback: IClassicBluetoothEventCallback)
Content copied to clipboard
Unregister the specified callback to not receive Classic Bluetooth event again.