Code example for ClipboardManager

Methods: setPrimaryClip

0
        } 
    } 
 
    private void setPrimaryClip(ClipData clip) {
        ClipboardManager clipboard = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
        clipboard.setPrimaryClip(clip);
    } 
 
    private void copyContent() { 
        final String text = getText();
        ClipboardManager clipboard = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
        clipboard.setPrimaryClip(ClipData.newPlainText(null, text));
        String toastText = String.format(getResources().getString(R.string.text_copied_toast), text);
        Toast.makeText(getContext(), toastText, Toast.LENGTH_SHORT).show();
    } 
 
    private void cutContent() { 
        final String text = getText();
        setPrimaryClip(ClipData.newPlainText(null, text));
        clear(); 
    }