方法一
\frameworks\base\core\res\res\values\config.xml
中有个属性:
<!-- Flag indicating that this device does not rotate and will always remain in its default
orientation. Activities that desire to run in a non-compatible orientation will be run
from an emulated display within the physical display. -->
<bool name="config_forceDefaultOrientation">false</bool>
这个属性控制默认竖屏的 APP 是否强制按系统默认方向显示,如果此时系统方向默认是横屏,当这个属性置为 true 时,默认竖屏的 APP 就将按类似于 Android 投屏的效果 显示在屏幕上。
此修改在某些 MTK 平台上,会出现问题,具体现象是:进入默认竖屏 APP 后,系统会强制将APP转为横屏显示,此时,APP 界面左侧 2/3 区域无法响应点击事件(驱动层正常上报事件)。
方法二
在保持上面的属性 config_forceDefaultOrientation = false
的前提下,修改 \frameworks\base\services\core\java\com\android\server\wm\WindowManagerService.java
中的代码,如下:
boolean updateOrientationFromAppTokensLocked(boolean inTransaction) {
long ident = Binder.clearCallingIdentity();
try {
int req = 0/* getOrientationLocked() */; ///修改这里,我这里因为默认方向是横屏,所以写0。
if (req != mForcedAppOrientation) {
mForcedAppOrientation = req;