Question

I want to know if a device is flat to the ground or not?

Flat Mode:

My Android device is placed flat on a table with its screen upside. Then it is laying flat to the ground.

Not Flat:

And when I picks up the device from its top corner - keeping its bottom corner still on table. Then it starts standing vertical to the ground. And Now it is not lying flat to the ground anymore.

Problems:

How can I know exactly using sensors and SensorEvents in android about this? TYPE_ORIENTATION is now deprecated. But still how can specific sensor values be used to determine if the device is flat to the ground or not. Where would I find such calculation?

I have explored some posts about sensors but I am still confused how my problem is going to get solved?

Related Posts:

How should I calculate azimuth, pitch, orientation when my Android device isn't flat?

Android Compass that can Compensate for Tilt and Pitch

Was it helpful?

Solution

You have to register for sensor type accelerometer and then see how to calculate the tilt at How to measure the tilt of the phone in XY plane using accelerometer in Android

For your purpose if the inclination in the above link is not zero (give or take a few degrees) then your device is lifted up.

OTHER TIPS

I would see if the device has a gyroscope and if not then use an accelerometer. Both in unison would be even better. With orientation it seems you are worried with rotation, hence the gyroscope. Accelerometers aren't as efficient at measuring rotation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top