我正在开发一个程序,允许用户通过使用 ddmlib 库在他的计算机屏幕上显示他的 android 手机(通过 USB 连接到计算机)的当前屏幕。我需要知道手机是横向模式还是纵向模式。
有没有办法从计算机上运行的程序中检查这个值?
最佳答案
这是我获取它的函数,但速度很慢。现在我正在寻找更快的解决方案。
private int getLandscape() {
int result = 0;
try {
String[] commands = new String[] { "adb", "-s", actualSerial,
"shell", "dumpsys input | grep 'SurfaceOrientation'" };
Runtime rt = Runtime.getRuntime();
Process pr;
pr = rt.exec(commands);
BufferedReader input = new BufferedReader(new InputStreamReader(
pr.getInputStream()));
String line = "";
line = input.readLine();
if (line != null) {
String[] lines = line.split(":");
result = Integer.parseInt(lines[1].trim());
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}
最慢的部分是从 BufferedReader 读取。
关于android - 使用 ddmlib.jar 获取 Android 设备方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5566553/