2017-08-29 177 views
0

我需要在設備啓動時應用某些adb命令。但是讓我們說,當我啓動我的應用程序時,我需要它。在我的Android應用程序中執行adb shell命令

adb shell settings put global policy_control immersive.navigation=* 

我在網上搜索,並與

Process p = Runtime.getRuntime().exec("settings put global policy_control immersive.navigation=*"); 

想出但unfortunally這COMAND不起作用。如果我將手機插入PC並直接通過命令窗口運行adb命令 - 一切正常。但是,當我從應用程序執行它 - 沒有任何工作,我甚至沒有看到日誌中的任何相關的錯誤。

我也試過這個: https://www.learn2crack.com/2014/03/android-executing-shell-commands.html 和像「ls/system/framework」這樣的命令有效。但是我需要的那個 - 不。

我的設備是紅米Note 3基於Android 6.0.1運行MIUI 8。我的項目在Eclipse中。

是否有可能執行這樣一個無根或沒有根?

+0

HTTPS ://developer.android.com/studio/tools/sdk/eclipse-adt.html –

回答

0

代替:

Process p = Runtime.getRuntime().exec("settings put global policy_control immersive.navigation=*"); 

嘗試:

Process p = Runtime.getRuntime().exec(new String[]{"settings", "put", "global", "policy_control", "immersive.navigation=*"); 

exec期望命令是一個字符串數組,其中所述第一字符串是命令和其餘的是它的參數

相關問題