Example usage for android.view.accessibility AccessibilityNodeInfo ACTION_PASTE

List of usage examples for android.view.accessibility AccessibilityNodeInfo ACTION_PASTE

Introduction

In this page you can find the example usage for android.view.accessibility AccessibilityNodeInfo ACTION_PASTE.

Prototype

int ACTION_PASTE

To view the source code for android.view.accessibility AccessibilityNodeInfo ACTION_PASTE.

Click Source Link

Document

Action to paste the current clipboard content.

Usage

From source file:com.ucmap.dingdinghelper.services.DingDingHelperAccessibilityService.java

/**
 * //w ww .j a  v a2s.  c  o  m
 */
private void setTextToView(AccessibilityNodeInfo node, String text) {
    Bundle arguments = new Bundle();
    arguments.putInt(AccessibilityNodeInfo.ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT,
            AccessibilityNodeInfo.MOVEMENT_GRANULARITY_WORD);
    arguments.putBoolean(AccessibilityNodeInfo.ACTION_ARGUMENT_EXTEND_SELECTION_BOOLEAN, true);
    node.performAction(AccessibilityNodeInfo.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY, arguments);
    /*?*/
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Bundle args = new Bundle();
        args.putCharSequence(AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE, text);
        node.performAction(AccessibilityNodeInfo.ACTION_SET_TEXT, args);
    } else {
        ClipData data = ClipData.newPlainText("reply", text);
        ClipboardManager clipboardManager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
        clipboardManager.setPrimaryClip(data);
        node.performAction(AccessibilityNodeInfo.ACTION_FOCUS); // ?
        node.performAction(AccessibilityNodeInfo.ACTION_PASTE); // 
    }

}