I need help getting information from the orientation sensor. As I saw in almost every tutorial / guide, values ββare passed to the event (onSensorChanged (SensorEvent event), in which they can be manipulated.
My problem is that I donβt want to keep the electromagnetic / orientation sensor constantly (for the sake of battery life). I want to be able to enable it, capture the current value and disable it. Is there any way to do this?
I did a few searches and found that I can try multithreading, but itβs not very convenient for me.
What I'm looking for is something like (sorry for the lack of formatting, I can't figure it out):
private void getOrientationNOW() {
m_SensorManager.registerListener(mySensorEventListener, m_MagneticSensor, SensorManager.SENSOR_DELAY_FASTEST);
m_SensorManager.unregisterListener(mySensorEventListener);
}
If possible, please help me!
Thank you all in advance!
source
share