1.首先进入github官网
2.搜索uiautomator
3.找到如下图:
4.在网站下载或者在eclipse里下
5导入到eclispe中
6.使用eclipse安装到手机
A.右键 Utf7Ime工程
B.Run As
C.Android Application
D.选择手机,然后点击Ok就可以了。
7.复制com 和 jp 到工程中
工程的目录是:
uiautomator-unicode-input-helper-master\UiAutomatorInputSample\src
8.代码
实现功能:
外部 传入中文参数,实现中文输入
uiautomator代码
public void testInput(){
//输入对象
UiObject edit = new UiObject(new UiSelector().className(EditText.class.getName()));
//获取dos输入的参数
Bundle b = getParams();
try {
//获取系统参数
String text =(String) b.get("edit");
//输入中文
edit.setText(Utf7ImeHelper.e(text));
} catch (UiObjectNotFoundException e) {
System.out.println("输入错误!");
}
}
DOS执行命令 java
String cmd1 ="你好";
//项目编码utf-8 转 dos编码gbk
String text = new String(cmd1.getBytes("utf-8"),"gbk");
BufferedReader br;
//dos下 执行的命令
String cmd ="adb shell uiautomator runtest Demo.jar --nohup -c " +
"com.demo.Demo#testInput -e edit "+text;
try {
//获取执行后的返回值
Process exec = Runtime.getRuntime().exec(cmd);
br = new BufferedReader(
new InputStreamReader(exec.getInputStream()));
String line =null;
while((line=br.readLine())!=null){
//line为空不输出
if(!line.equals("")){
//输出line内容
System.out.println(line);
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}