【发布时间】:2015-05-01 08:46:44
【问题描述】:
我有一个带有 root(开箱即用)的Android PC 连接到始终以横向显示的外接显示器(HDMI 和 USB),即使我的应用程序在 Activity 中指定了纵向Manifest 中的声明:
android:screenOrientation="portrait"
我正在尝试从此SO post 执行以下命令来强制纵向:
proc = Runtime.getRuntime().exec("adb shell content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:0");
int exitVal = proc.waitFor();
这应该将屏幕设置为纵向,但显示始终保持横向。没有记录异常。
我也使用了以下方法但没有成功:
process = Runtime.getRuntime().exec("content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:0");
process = Runtime.getRuntime().exec(new String[]{"su","-c","content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:0"});
在这两种情况下,退出值都是 [0]。这意味着命令正常终止。
Android PC 上只有一个 USB 端口和一个微型 USB 端口(仅电源/无数据)。启用调试后,我无法在 DDMS 中枚举设备,也无法从 BASH 执行 shell 命令,将我的开发 PC 连接到 Android PC 上的微型 USB 端口。所以,我正在尝试从我的 Android 应用程序中执行此操作。
请指教
【问题讨论】:
标签: android shell adb screen-orientation