adb shell settings ....


Android4.2的源碼android-17\com\android\commands目錄下較之前的版本多了一個settings命令,查看其中的SettingsCmd.java文件,末尾有命令的幫助信息:

private static void printUsage() {

        System.err.println("usage:  settings [--user NUM] get namespace key");

        System.err.println("        settings [--user NUM] put namespace key value");

        System.err.println("\n'namespace' is one of {system, secure, global}, case-insensitive");

        System.err.println("If '--user NUM' is not given, the operations are performed on the owner user.");

    }

選項中的key為什么值,很難從幫助信息中看出,從代碼中查看該key值是在android.provider.Settings中定義了。

http://developer.android.com/reference/android/provider/Settings.System.html

該命令可以很方便的更改系統設置中的參數(如修改系統默認輸入法),給出幾個使用該命令的例子:

#獲取系統默認輸入法

#默認搜狗輸入法

C:\Users\Administrator>adb shell settings get secure default_input_method

com.sohu.inputmethod.sogouoem/.SogouIME

 

#默認為Appium使用中文輸入時安裝的輸入法

C:\Users\Administrator>adb shell settings get secure default_input_method

io.appium.android.ime/.UnicodeIME

 

#put命令更改默認輸入法(將io.appium.android.ime/.UnicodeIME改為com.sohu.inputmethod.sogouoem/.SogouIME)

C:\Users\Administrator>adb shell settings put secure default_input_method com.sohu.inputmethod.sogouoem/.SogouIME

#獲取亮度是否為自動獲取

C:\Users\Administrator>adb shell settings get system screen_brightness_mode

1

#獲取當前亮度值

C:\Users\Administrator>adb shell settings get system screen_brightness

30

#更改亮度值(亮度值在0—255之間)

C:\Users\Administrator>adb shell settings put system screen_brightness 150

#獲取屏幕休眠時間

C:\Users\Administrator>adb shell settings get system screen_off_timeout

15000

#更改休眠時間,10分鍾

C:\Users\Administrator>adb shell settings put system screen_off_timeout 600000

#獲取日期時間選項中通過網絡獲取時間的狀態,1為允許、0為不允許

C:\Users\Administrator>adb shell settings get global auto_time

1

#更改該狀態,從1改為0

C:\Users\Administrator>adb shell settings put global auto_time 0

以及獲取、修改wifi狀態(wifi_on)、飛行模式(airlpane_mode_on)等,這里也是appium中getNetworkConnection獲得設備網絡狀態的方法。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM