是否可以发送过去的命令以便将文本粘贴到当前聚焦的编辑文本中,我正在使用RFID阅读器硬件。情形:
在硬件RFID阅读器按钮触发器上,我将source as null
@覆盖 public void onAccessibilityEvent(AccessibilityEvent event){ Log.e(" -onAccessibilityEvent - "," ----------");
AccessibilityNodeInfo source2 = event.getSource();
if (source2 == null) {
return;
}
// if (source2 != null && event.getEventType() == AccessibilityEvent.TYPE_VIEW_CLICKED) {
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("label", r);
clipboard.setPrimaryClip(clip);
source2.performAction(AccessibilityNodeInfo.ACTION_PASTE);
}
}
我知道如何使用ClipboardManager复制文本。
答案 0 :(得分:-1)
@Override
protected boolean onKeyEvent(KeyEvent event) {
case KeyEvent.KEYCODE_VOLUME_DOWN:
ClipboardManager clipboardManager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clipData = ClipData.newPlainText("Amitesh", "abc");
clipboardManager.setPrimaryClip(clipData);
focusedNodeInfo.performAction(AccessibilityNodeInfo.ACTION_PASTE);
return false;
}