由于目前adb shell input 不支持unicode字符输入,因此绕个小弯路实现中文输入
链接:https://github.com/bingwei/inputchineseviaadb
安装apk文件(可以从pyscript下找到)
运行python pyscript/testScript.py试验
最终输入的字符将被保存到粘贴板里。
原理:使用unicode字符原样输出,然后再转化为encoded字符。
核心代码
输入端:
1. 标识脚本文件为支持utf-8字符集
#!-*- coding: utf-8 -*-
2. 使用%r原样输入unicode字符
os.system("adb shell input text %r"%u"黑色“)
转换端(apk):
1. 输入到editText中的字符为转义后的unicode,因此需要反转义,这里用到了StringEscapeUtils
下载:http://commons.apache.org/lang/download_lang.cgi
API:http://commons.apache.org/lang/api-2.1/org/apache/commons/lang/StringEscapeUtils.html
import org.apache.commons.lang3.StringEscapeUtils;
StringEscapeUtils.unescapeJava(editText.getText().toString().replace("u\\", "\\"))
反转义之后复制到clipboard就可以了