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)
}
}
I'm sorry, but I didn't actually try it.
Why don't you set the fourth argument maxReportLatencyUs in registerListener to 10 seconds?
If it doesn't work, it might be better to do something about it on the app side.
You can use debounce in the coroutines library, so you can bundle it here every 10 seconds.
© 2024 OneMinuteCode. All rights reserved.