As in the picture, I want to get the pitch, that is, I want to check whether the device is parallel to the ground.
Asked
Active
Viewed 94 times
1
-
1http://stackoverflow.com/questions/10291322/what-is-the-alternative-to-android-orientation-sensor/10291428#10291428 this will help you – Anjali Oct 04 '16 at 05:44
-
1http://stackoverflow.com/questions/11175599/how-to-measure-the-tilt-of-the-phone-in-xy-plane-using-accelerometer-in-android/15149421#15149421 – Hoan Nguyen Oct 05 '16 at 01:30
3 Answers
1
I register the Orientation like this:
sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
sensor = sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
and compared the values (in onSensorChanged
) to the ones that the sensor would give if the phone was placed parallel to the ground.

izSaad
- 579
- 6
- 25
0
use the following code snippet it works fine...
private boolean isLandscape()
{
return Activity.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
}

Nitesh Pareek
- 362
- 2
- 10
-
I don't want to check if its landscape or now (if that's what this snippet is doing), I want to e.g, ring an alert if my device is put on a table since that would be 'parallel to the ground'. – izSaad Oct 04 '16 at 06:13
-1
Try this to get device orientation
getResources().getConfiguration().orientation
https://developer.android.com/reference/android/content/res/Configuration.html#ORIENTATION_LANDSCAPE

raasesh
- 161
- 11