I need to determine the orientation change of an Android device without manually playing with the sensor data, while maintaining the orientation of the activity towards some orientation.
onConfigurationChange will not work as my activity will not rotate.
Playing with the sensor data to detect a change in orientation, I believe that as an invention of the wheel, since the android already has a built-in implementation of the algorithm for detecting a change in the orientation of the device. And on the other hand, detecting a change in orientation is not a simple check like this.
public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() != Sensor.TYPE_ACCELEROMETER || event.values.length < 3) {
return;
}
if (event.values[1] < 6.5 && event.values[1] > -6.5) {
if (orientation!=1) {
Log.d("Sensor", "Protrait");
}
orientation=1;
} else {
if (orientation!=0) {
Log.d("Sensor", "Landscape");
}
orientation=0;
}
}
It really requires real data processing, such as filtering from noise and sudden short jolts / turns.
, , ? ( , , onConfigurationChange )