解决AndroidDriver不能输入中文

android-server修改WebViewAction.java
新增

private static boolean isChinese(char c) {
Character.UnicodeBlock ub = Character.UnicodeBlock.of(c);
if (ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
|| ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS
|| ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A
|| ub == Character.UnicodeBlock.GENERAL_PUNCTUATION
|| ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION
|| ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS) {
return true;
}
return false;
}

修改sendKeys(WebView webview, CharSequence... text)

for (CharSequence sequence : inputText) {
for (int i = 0; i < sequence.length(); i++) {
char c = sequence.charAt(i);
int code = AndroidKeys.getKeyEventFromUnicodeKey(c);
if (code != -1) {
keyEvents.addLast(new KeyEvent(KeyEvent.ACTION_DOWN, code));
keyEvents.addLast(new KeyEvent(KeyEvent.ACTION_UP, code));
} else {
if (isChinese(c)) {
String str = String.valueOf(c);
KeyEvent event = new KeyEvent(0, str, 0, 0);
keyEvents.add(event);
} else {
keyEvents.addAll(Arrays.asList(
characterMap.getEvents(new char[]{c})));
}
}
}
}

你可能感兴趣的:(手机自动化测试)