How do I set the build for Landscape mode only?

4,221 views
Skip to first unread message

Dave McLaughlin

unread,
Jun 17, 2020, 10:29:39 AM6/17/20
to android-porting
I want to set the build so that the only screen orientation available is landscape.

I have disabled autorotation but one app I run always changes the display to portrait and this is not ideal on a landscape only display. It changes back to landscape on exit but is not very user friendly from the 90 deg angle. 

Where in the build can I make changes that prevent any orientation changes by any app?

Budhdi Prakash Sharma

unread,
Jun 23, 2020, 10:54:49 AM6/23/20
to android-porting

To get an Android application to display in landscape mode only (to lock it in landscape mode), add this line to your Activity definition in the AndroidManifest.xml file:

android:screenOrientation="landscape"

For example, I’m writing an Android football game right now, and this is the definition for my main activity in the Android manifest file:

<activity
    android:name=".MainActivity"
    android:screenOrientation="landscape"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

Dave McLaughlin

unread,
Jun 24, 2020, 10:40:57 AM6/24/20
to android-porting
Yeah, that works for each application but I was referring to the platform build itself not offering a portrait orientation as an option, similar to what it does when running on HDMI displays. 

I was given a solution that works but sadly, the running app is given a simulated portrait view within the landscape orientation which doesn't reset back to full landscape when that app exists but I have added this to my main app so that takes care of the issue and doesn't give me a rotate 90 deg portait view/ Not ideal but it works.

Trần Kha

unread,
Jul 7, 2020, 2:28:37 PM7/7/20
to android-porting
Hi Dave,

Please refer below steps to force orientation to landscape:

1. Make sure only landscape permission is available on your build environment

Only add android.hardware.screen.landscape.xml to your makefile by below command:

PRODUCT_COPY_FILES += frameworks/native/data/etc/android.hardware.screen.landscape.xml:system/etc/permissions/android.hardware.screen.landscape.xml \

Remove android.hardware.screen.portrait.xml if it exists

2. Add an overlay to force landscape mode
Assume you have device/company/device_x

Create a config.xml file and put it in

device/company/device_x/overlay/framework/base/res/res/values

Contents of config.xml:

<resources>
<bool name="config_forceDefaultOrientation">true</bool>
</resources>

3. Make sure your overlay in config.xml is used

PRODUCT_PACKAGE_OVERLAYS += device/company/device_x/overlay

Done! Your system is always landscape!

Note: This solution only works on Android P or older Android version. From Android Q, Google changes to use new solution.

Limitation: The app which sets portrait as orientation in AndroidManifest.xml can’t display properly! Ex: Antutu Benmark.

By the way, I had found solution for above limitation by creating a broadcast service which tried to convert rotation of the application. But i just forgot the reference. I will try to find it and share you later!

Best Regards,
KHA Tran




Dave McLaughlin

unread,
Sep 2, 2020, 10:42:47 AM9/2/20
to android-porting
I have Android 7.1 and I implemented all of the changes you indicated, although you do indicate P or higher I thought I would try it. During the boot, the boot logo was still in portrait mode due to the fact that the default orientation of the LCD display is portrait mode (the timings are for 800x1280 and not 1280x800)

When I flash the new OS to the board and then boot it and Android finally starts, the display is initially in landscape mode but quickly changes to portrait. Subsequent reboots are straight into portrait. I've not been able to track down which part of the source is selecting portrait.

By the way, the exact same build running on the same processor board but with an 800x480 LCD that is default landscape timing, comes up as landscape. 

rashad roberson

unread,
Sep 2, 2020, 7:05:18 PM9/2/20
to davemcla...@gmail.com, android-porting
Thank so much for the I was trying to upgrade and had not been able succeeded 

--
--
unsubscribe: android-porti...@googlegroups.com
website: http://groups.google.com/group/android-porting

---
You received this message because you are subscribed to the Google Groups "android-porting" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-porti...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-porting/150fb306-42d2-45c2-9c67-f75d1961186en%40googlegroups.com.

CHANG YONGHO

unread,
Nov 29, 2020, 7:14:14 PM11/29/20
to android-porting
안녕하세요.

landscape feature 설정을 해보는 건 어떤가요?

android/frameworks/native/data/etc/handheld_core_hardware.xml

ignore "android.hardware.screen.portrait"

감사합니다.
2020년 9월 3일 목요일 오전 8시 5분 18초 UTC+9에 rashadro...@gmail.com님이 작성:

Developer 420

unread,
Mar 10, 2021, 4:39:05 PM3/10/21
to android-porting
Does any one have configuration to make the build for landscape only  mode in AOSP 10?

Thanks In Advance
Reply all
Reply to author
Forward
0 new messages