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获得设备网络状态的方法。

posted on 2015-02-09 09:26  Rosepotato  阅读(11336)  评论(0编辑  收藏  举报