是否可以从应用程序执行亚行的shell命令? [英] Is it possible to execute ADB shell commands from app?
问题描述
我有一个 Android的PC 的是根(乱盒)连接到外部显示器(HDMI和放大器; USB)始终以横向显示,即使我的应用程序指定清单中的活动宣言画像:
I have an Android PC with root (out-of-box) connected to an external monitor (HDMI & USB) that always displays in landscape, even though my app specifies portrait in the activity declaration in Manifest:
android:screenOrientation="portrait"
我想执行此以下命令<一href="http://stackoverflow.com/questions/13381828/is-it-possible-to-execute-adb-commands-through-my-android-app">SO帖子给力纵向:
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();
这应该设置在屏幕上的肖像,但显示始终保持在景观。没有例外的记录。
This should set the screen to portrait, but the display always remains in landscape. No exceptions are recorded.
我也用没有成功如下:
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]。这意味着正常终止命令。
In both cases, the exit value is [0]. Which means the command terminated normally.
只有一个USB端口,和一个微USB端口(只功率/无数据)的机器人的PC上。如果启用了调试,我无法枚举设备DDMS,也没有从BASH执行shell命令连接我开发PC和Android的PC上的micro USB接口。所以,我想从我的Android应用程序做到这一点。
There is only one USB port, and one micro USB port (Power only/no data) on the Android PC. With debugging enabled, I cannot enumerate the device in DDMS, nor execute shell commands from BASH connecting my dev PC to the micro USB port on the Android PC. So, I am trying to do this from my Android app.
请指教
推荐答案
在设备上执行的命令,没有必要preFIX用亚行外壳
,你的java code中的设备上运行本身所以只是把它关闭,只需要运行下面的命令
When executing a command on the device there is no need to prefix it with adb shell
, your java code runs on the device itself so just drop it off and just run the following command
content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:0"
只是一个快速的音符,当你这样做,你告诉了Android设备上通过亚行连接其它Android设备执行此命令
Just a quick note, when you do so, you tell the Android device to execute this command on another android device that is connected to it via ADB
这篇关于是否可以从应用程序执行亚行的shell命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!