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;

}

}

}

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐