-1

Is it possible to detect current orientation of an android device using sensors like Gyroscope? By orientation I mean whether the device is held vertical to ground or placed horizontally on a surface etc...

Thanks in advance.

sreejith.virgo
  • 333
  • 1
  • 4
  • 15

3 Answers3

0

The current configuration, as used to determine which resources to retrieve etc, as available from the Resources' Configuration object as:

getResources().getConfiguration().orientation

Check this link too

Atish Agrawal
  • 2,857
  • 1
  • 23
  • 38
0

Try this:

Activity.getResources().getConfiguration().orientation

It will returns current activity orientation

For more information click Here

Community
  • 1
  • 1
Lokesh
  • 5,180
  • 4
  • 27
  • 42
0

Yes, You can use Sensor's data to analyse the position of a device.

Please refer to the standard documentation on how to use gyroscope: http://developer.android.com/reference/android/hardware/SensorEvent.html

Also, a possible duplicate of:

Community
  • 1
  • 1
alandarev
  • 8,349
  • 2
  • 34
  • 43
  • I'm not looking for screen orientation, but device's orientation axis X,Y and Z – sreejith.virgo Mar 26 '14 at 05:09
  • @sreejith.virgo and I gave you? – alandarev Mar 26 '14 at 08:15
  • I mean I had already gone through the documentation and try searching, but it only provide me ways to find the change in position. But not the position at a moment. – sreejith.virgo Mar 26 '14 at 10:53
  • @sreejith.virgo you have to use the event listener anyway, sadly that is the recommended and only way. Register listener, wait for data, remove listener. No, there is no Sensor.getValue method – alandarev Mar 26 '14 at 11:38
  • Ya, I found the same in documentation.But that wouldn't do what I exactly want. Anyway thanks for your time n comments :) – sreejith.virgo Mar 27 '14 at 06:17