Android4.2的源碼android-17\com\android\commands目錄下較之前的版本多了一個settings命令,查看其中的SettingsCmd.java文件,末尾有命令的幫助信息:
1 private static void printUsage() { 2 System.err.println("usage: settings [--user NUM] get namespace key"); 3 System.err.println(" settings [--user NUM] put namespace key value"); 4 System.err.println("\n'namespace' is one of {system, secure, global}, case-insensitive"); 5 System.err.println("If '--user NUM' is not given, the operations are performed on the owner user."); 6 }
選項中的key為什么值,很難從幫助信息中看出,從代碼中查看該key值是在android.provider.Settings中定義了。
http://developer.android.com/reference/android/provider/Settings.System.html
該命令可以很方便的更改系統設置中的參數(如修改系統默認輸入法),給出幾個使用該命令的例子:
1 #獲取系統默認輸入法 2 #默認搜狗輸入法 3 C:\Users\Administrator>adb shell settings get secure default_input_method 4 com.sohu.inputmethod.sogouoem/.SogouIME 5 6 #默認為Appium使用中文輸入時安裝的輸入法 7 C:\Users\Administrator>adb shell settings get secure default_input_method 8 io.appium.android.ime/.UnicodeIME 9 10 #put命令更改默認輸入法(將io.appium.android.ime/.UnicodeIME改為com.sohu.inputmethod.sogouoem/.SogouIME) 11 C:\Users\Administrator>adb shell settings put secure default_input_method com.sohu.inputmethod.sogouoem/.SogouIME
1 #獲取亮度是否為自動獲取 2 C:\Users\Administrator>adb shell settings get system screen_brightness_mode 3 1 4 #獲取當前亮度值 5 C:\Users\Administrator>adb shell settings get system screen_brightness 6 30 7 #更改亮度值(亮度值在0—255之間) 8 C:\Users\Administrator>adb shell settings put system screen_brightness 150
1 #獲取屏幕休眠時間 2 C:\Users\Administrator>adb shell settings get system screen_off_timeout 3 15000 4 #更改休眠時間,10分鍾 5 C:\Users\Administrator>adb shell settings put system screen_off_timeout 600000
1 #獲取日期時間選項中通過網絡獲取時間的狀態,1為允許、0為不允許 2 C:\Users\Administrator>adb shell settings get global auto_time 3 1 4 #更改該狀態,從1改為0 5 C:\Users\Administrator>adb shell settings put global auto_time 0
以及獲取、修改wifi狀態(wifi_on)、飛行模式(airlpane_mode_on)等,這里也是appium中getNetworkConnection獲得設備網絡狀態的方法。