I tried getOrientation()
to get the orientation value but it always returns 0!
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
getOrientation()
is deprecated. Instead, trygetRotation()
.I had the same problem on NexusOne SDK 2.3.
This solved it: Check orientation on Android phone.
If you want to know if the content currently displayed is in landscape mode or portrait (possibly completely independent of the phone's physical rotation) you can use:
getResources().getConfiguration().orientation
Developer Documentation
To avoid use of Deprecated methods use the Android Configuration class found here. It works since API lvl 1 and still works on the latest android devices. (Not deprecated).
As and example consider the following code snippet:
Best of luck- hope this answer helps whoever runs into it.
getOrientation() is deprecated but this is not neccesarily the root of your problem. It is true that you should use getRotation() instead of getOrientation() but you can only use it if you are targeting Android 2.2 (API Level 8) or higher. Some people and even Googlers sometimes seem to forget that.
As an example, on my HTC desire running Android 2.2. getOrientation() and getRotation() both report the same values:
It does not report when you put it "on its head" (rotate 180, that would be the value 2). This result is possibly device-specific.
First of all you should make clear if you use an emulator or a device. Do you know how to rotate the emulator? Then I would recommend to create a small test program with a onCreate() Method like this:
Check if the screen of your your device has been locked in the device settings Settings > Display > Auto-Rotate Screen. If that checkbox is unchecked, Android will not report orientation changes to your Activity. To be clear: it will not restart the activity. In my case I get only 0, like you described.
You can check this from your program if you add these lines to onCreate()
It will return 0 if Auto-Rotate is off and 1 if Auto-Rotate is on. Another try. In your original program you might have set in manifest
Same effect, but this time for your activity only. If you made the small test program this possibilty would have been eliminated (that's why I recommend it).
Remark: Yes the whole orientation / rotation topic is an "interesting" topic indeed. Try things out, use Log.d(), experiment, learn.