SensoriaHandler.java
Purpose
The SensoriaHandler class in the Android module handles communication with Sensoria Smart Garment devices. It interfaces with the Sensoria SDK for BLE management, sensor data streaming, connection status, and error handling. It enables bidirectional interaction between Flutter and native Android using Flutter’s EventChannel.
Key Responsibilities
Initialize and manage two Sensoria cores concurrently.
Bind to the Sensoria Service and manage Bluetooth GATT callbacks.
Handle streaming events and propagate them to Flutter.
Serialize connection status and timestamps to JSON for diagnostics.
Imports
Includes Android system APIs, BLE classes, and Sensoria SDK:
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCallback;
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothDevice;
import com.sensoria.sensorialibrary.*;
Also includes:
EventChannel,MethodChannelfrom FlutterHandler,Looper,Gson, andToast
Initialization Flow
Service Binding
SACore sacore1 = null; SADevice device1 = null;
Each core-device pair is initialized upon service readiness.
Permission Handling Requests and verifies Bluetooth and Location permissions required by the Sensoria SDK.
Sensor Binding Sensoria devices are discovered and connected using:
sacore1.setSAServiceInterface(...); sacore1.connectSensor(...)
Status Tracking
Tracks timestamps and provides structured output via:
public String getCurrentStatus(int coreIndex)
Returns a JSON object with keys:
lastDataTimestampSensoriaCorelastDataWriteTimestampisConnected
Stream Handling
Uses Flutter’s EventSink to push live updates:
eventSink.success(message)
This allows Flutter to reflect real-time BLE status and connectivity events from Sensoria devices.
Best Practices
Supports dual-core setup for concurrent smart garments.
Strong null-checks and error logs for connection failure.
Timestamp tracking enhances debugging and health monitoring.
Dependencies
Sensoria SDK (
sensorialibrary)Gson for status serialization
Android BLE and permission management
Notes
All interactions use Android’s main thread via
HandlerandLooper.Designed to integrate seamlessly with
MainActivity.javaand Flutter event channels.