|
@@ -14,22 +14,24 @@ class SensorStreamHandler() : EventChannel.StreamHandler {
|
|
|
private var sensor: Sensor? = null
|
|
|
private lateinit var context: Context
|
|
|
private lateinit var sensorName: String
|
|
|
+ private var sensorType: Int = Sensor.TYPE_STEP_COUNTER
|
|
|
private lateinit var flutterPluginBinding: FlutterPlugin.FlutterPluginBinding
|
|
|
|
|
|
constructor(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding, sensorType: Int) : this() {
|
|
|
this.context = flutterPluginBinding.applicationContext
|
|
|
+ this.sensorType = sensorType
|
|
|
this.sensorName = if (sensorType == Sensor.TYPE_STEP_COUNTER) "StepCount" else "StepDetection"
|
|
|
+ this.flutterPluginBinding = flutterPluginBinding
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onListen(arguments: Any?, events: EventChannel.EventSink?) {
|
|
|
+ println("SensorStreamHandler onListen $sensorName $sensor")
|
|
|
sensorManager = context.getSystemService(Context.SENSOR_SERVICE) as SensorManager
|
|
|
sensor = if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
|
|
|
sensorManager!!.getDefaultSensor(sensorType, true)
|
|
|
}else{
|
|
|
sensorManager!!.getDefaultSensor(sensorType)
|
|
|
}
|
|
|
- this.flutterPluginBinding = flutterPluginBinding
|
|
|
- }
|
|
|
-
|
|
|
- override fun onListen(arguments: Any?, events: EventChannel.EventSink?) {
|
|
|
- println("SensorStreamHandler onListen $sensorName $sensor")
|
|
|
if (sensor == null) {
|
|
|
if(this.sensorName == "StepDetection") {
|
|
|
sensorEventListener = object : StepDetector() {
|