[英]Link adb path from resource to execute shell commands in Java application
[英]Is it possible to execute ADB shell commands from app?
我有一台帶有root (開箱即用)的Android PC連接到外部顯示器(HDMI和USB),它始終以橫向顯示,即使我的應用程序在Manifest中的活動聲明中指定了portrait:
android:screenOrientation="portrait"
我試圖從這個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();
這應該將屏幕設置為縱向,但顯示屏始終保持橫向顯示。 沒有記錄例外情況。
我也使用了以下內容但沒有成功:
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將我的開發PC連接到Android PC上的micro USB端口執行shell命令。 所以,我試圖通過我的Android應用程序執行此操作。
請指教
在設備上執行命令時,不需要在adb shell
前面添加命令,您的java代碼在設備上運行,所以只需將其關閉然后運行以下命令
content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:0"
只需快速說明,當您這樣做時,您告訴Android設備在另一個通過ADB連接到它的Android設備上執行此命令
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.