private void saveToClipboard(@NonNull CharSequence selectedText, @Nullable Intent intent) {
        if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
            android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
            clipboard.setText(selectedText);
        } else {
            android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData.Item item = new ClipData.Item(selectedText, intent, null);
            android.content.ClipData clip = new ClipData(null, new String[]{ClipDescription.MIMETYPE_TEXT_PLAIN}, item);
            clipboard.setPrimaryClip(clip);
        }
    }
private void saveToClipboard(@NonNull CharSequence selectedText, @Nullable Intent intent) {
        if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
            android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
            clipboard.setText(selectedText);
        } else {
            android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData.Item item = new ClipData.Item(selectedText, intent, null);
            android.content.ClipData clip = new ClipData(null, new String[]{ClipDescription.MIMETYPE_TEXT_PLAIN}, item);
            clipboard.setPrimaryClip(clip);
        }
    }
private void saveToClipboard ( @ NonNull CharSequence selectedText , @ Nullable Intent intent ) { if ( android . os . Build . VERSION . SDK_INT < android . os . Build . VERSION_CODES . HONEYCOMB ) { android . text . ClipboardManager clipboard = ( android . text . ClipboardManager ) getContext ( ) . getSystemService ( Context . CLIPBOARD_SERVICE ) ; clipboard . setText ( selectedText ) ; } else { android . content . ClipboardManager clipboard = ( android . content . ClipboardManager ) getContext ( ) . getSystemService ( Context . CLIPBOARD_SERVICE ) ; ClipData . Item item = new ClipData . Item ( selectedText , intent , null ) ; android . content . ClipData clip = new ClipData ( null , new String [ ] { ClipDescription . MIMETYPE_TEXT_PLAIN } , item ) ; clipboard . setPrimaryClip ( clip ) ; } }
Save the selected text and intent in ClipboardManager
Save the selected text and intent in ClipboardManager