Search code examples
androiddevicescreen-orientationlandscape-portrait

How to detect physically single-orientation (non-rotating) Android device programmatically?


We all know that Android was invented for handheld mobile devices but now there are lots of non-mobile devices you'd never dream of picking up and rotating such as TVs, and if I'm not mistaken even PCs (or things that closely resemble PCs) that run on Android. For example the ViewSonic VSD231 looks to me like something you'd never pick up and rotate.

My Android app is only meant to run in portrait mode. It programmatically locks the screen in portrait. So if you open it up on a physically landscape-only device, you're looking at a sideways app with sideways writing.

Does Android yet have a way to detect physically single-orientation devices? Or will it always be that users of such devices simply need to return apps they discover only work sideways on their device? Seems like that could generate some bad reviews and should be avoided if at all possible.


Solution

  • Put this in your manifest:

    <uses-feature
        android:name="android.hardware.screen.portrait"
        android:required="true" />
    

    Then the app will not appear in the Play Store for devices that do not support portrait orientation. See the docs for filters and the uses-feature tag.