UiObject中中文输入问题

1.首先进入github官网

网址:https://github.com/

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();
        }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值