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