android辅助输入,Android辅助功能AccessibilityService自动全选择文字粘贴模拟输入
viewIds, String text){AccessibilityNodeInfo root = getRootInActiveWindow();if(root == null) return;for (String id : viewIds){final Listlist = root.findAccessibilityNodeInfosByViewId(id);if(list != nul
viewIds, String text){
AccessibilityNodeInfo root = getRootInActiveWindow();
if(root == null) return;
for (String id : viewIds){
final Listlist = root.findAccessibilityNodeInfosByViewId(id);
if(list != null && !list.isEmpty()){
AccessibilityNodeInfo info = list.get(0);
//粘贴板
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("label", text);
clipboard.setPrimaryClip(clip);
CharSequence txt = info.getText();
if(txt == null) txt = "";
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
Bundle arguments = new Bundle();
arguments.putInt(AccessibilityNodeInfo.ACTION_ARGUMENT_SELECTION_START_INT, 0);
arguments.putInt(AccessibilityNodeInfo.ACTION_ARGUMENT_SELECTION_END_INT, txt.length());
info.performAction(AccessibilityNodeInfo.ACTION_FOCUS);
info.performAction(AccessibilityNodeInfo.ACTION_SET_SELECTION, arguments);
info.performAction(AccessibilityNodeInfo.ACTION_PASTE);
}
break;
}
}
}
更多推荐
所有评论(0)