- Home /
Can unity get the native orientation of an android device?
Hi everyone. This is a follow on question from :
answers.unity3d.com/questions/142961/android-accelerometer-inputacceleration-linked-to.html
It seems that the source of my original problem is that android tablets, and android phones have different native orientations of the accelerometer in relation to the screen.
please see the diagram at the bottom of this page.
http://developer.nvidia.com/content/android-tablets-are-here
in short.
landscape tablets see x and y accelerometer readings differently.
they see y as up/down from a landscape position. this would be x on a phone.
How can I detect this?
Answer by almo · Jul 13, 2011 at 04:13 PM
I think you could do it like Tilt 2 Live, a game on iPhone which supports different orientations.
Have a "calibrate" screen where it asks the user to hold the device as he will while playing. Read the data that comes in, and set that as the neutral orientation. Maybe add a snap to certain axes or angles (like 45, 60 or 90).
Thanks for the prompt reply almo. This is probably the route I'll go down, however hopefully unity can support this kind of thing in the future, rather then having to work around it.
Does anyone have a definitive answer on if this is possible or not?
I think it's not a Unity problem. It's whether or not Android devices will tell you what their "default" orientation is.
Answer by ocarson · Jul 22, 2011 at 02:42 PM
I've had to revisit this problem.
There is a way to detect the default orientation of an android device in the sdk, and automatically adjust the accelerometer values as outlined in this blogpost on the android blog.
http://android-developers.blogspot.com/2010/09/one-screen-turn-deserves-another.html
Now it doesn't look like Unity allows me access to this data without writing a plugin. Surely something so simple should be implemented in the Screen class? Like Screen.defaultOrientation or Screen.autoAdjustAccellerometer?
Add it to the feature request list. http://feedback.unity3d.com/forums/15792-unity
Answer by Billboard · Nov 15, 2012 at 10:06 AM
There's a solution courtesy of Ralph Barbagallo using Unity's access to AndroidJavaClass - see Detecting Android Tablets and Phones in Unity3D
Your answer
![](https://koobas.hobune.stream/wayback/20220612142552im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Setting Accelerometer Frequency on Android 0 Answers
accelerometer speed 1 Answer
Player Movement when phone shakes 0 Answers
Accelerometer axis differences on Android and iOS? 1 Answer
android phone vs tablet question 1 Answer