Appium-切换输入法

在实际工作中,可能会使用到切花输入法

//
查看系统当前的输入法 adb shell settings get secure default_input_method //获取当下系统的所有输入法 adb shell ime list //获取当前的可用输入法 adb shell ime list -s com.google.android.googlequicksearchbox/com.google.android.voicesearch.ime.VoiceInputMethodService com.google.android.inputmethod.latin/com.android.inputmethod.latin.LatinIME //设置当前的输入法 adb shell settings put secure default_input_method com.sohu.inputmethod.sogou/.SogouIME
adb shell ime set com.sohu.inputmethod.sogou/.SogouIME
//获取当前的输入法 adb shell settings get secure default_input_method com.sohu.inputmethod.sogou/.SogouIME //设置当前的输入法 adb shell settings put secure default_input_method com.sohu.inputmethod.sogou/.SogouIME

 

通过代码来调用cmd命令,可以通过定义一个方法,可以将该方法放入utils工具包中

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import org.apache.log4j.Logger;

public class ExcuteAdbShell {
    public static Logger logger = Logger.getLogger(ExcuteAdbShell.class);

    public void ExcuteAdbShell() {

    }

    /**
     * 执行adb命令
     *
     * @param s 要执行的命令
     */
    public void excuteAdbShell(String s) {
        Runtime run = Runtime.getRuntime();
        try {
            Process p = run.exec(s);                  //执行CMD命令

            BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream(), Charset.forName("GBK")));
            String lineMes;
            while ((lineMes = br.readLine()) != null)
//                System.out.println(lineMes);// 打印输出信息
                logger.info(lineMes);
            //检查命令是否执行失败。
            if (p.waitFor() != 0) {
                if (p.exitValue() == 1)//0表示正常结束,1:非正常结束
//                    System.err.println("命令执行失败!");
                    logger.info("命令执行失败");
            }
            br.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

 

posted @ 2020-10-19 18:59  布谷鸟的春天  阅读(546)  评论(0编辑  收藏  举报