I want to get sensor values regularly in a certain period of time with kotlin.

Asked 2 years ago, Updated 2 years ago, 92 views

I created an Android app using kotlin and wanted to get sensor information at regular intervals (10 second intervals), but I didn't know how to do it, so I tried to get sensorManager.registerListener(this,mSensor,SensorManager.SENSOR_DELAY_UI) as sensorManager.registerListener(this,mSensor,100000) in the source code below.

Is it possible to change the interval?
Thank you for your cooperation.

val sensorManager:SensorManager=getSystemService(Context.SENSOR_SERVICE) as SensorManager
sensors=sensorManager.getSensorList (Sensor.TYPE_ALL)
if(sensors.size>0){
    for (i in 0..sensors.size-1) {
        valmSensor —Sensor=sensors.get(i);
        sensorManager.registerListener(this,mSensor,SensorManager.SENSOR_DELAY_UI)
    }
}

android kotlin

2022-09-29 21:41

1 Answers

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.