Reputation: 145
I want to read orientation of the phone. However when I use
mOrientation = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
It shows a warning The field Sensor.TYPE_ORIENTATION is deprecated.
I also have a warning when reading the gyroscope value.
Could someone help me to read these two data. Thanks in advance.
Upvotes: 0
Views: 143
Reputation: 1584
You can check out this post: Check orientation on Android phone
In short, use
getResources().getConfiguration().orientation
Of course, do not setup orientation by yourself in the manifest.xml.
Upvotes: 1
Reputation: 24853
The current configuration, as used to determine which resources to retrieve etc, as available from the Resources' Configuration object as:
getResources().getConfiguration().orientation
http://developer.android.com/reference/android/content/res/Configuration.html#orientation
or
mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
mDisplay = mWindowManager.getDefaultDisplay();
Log.d("ORIENTATION_TEST", "getOrientation(): " + mDisplay.getOrientation());
Upvotes: 1