Code example for ClipboardManager

Methods: getPrimaryClip

0
        clear(); 
    } 
 
    private ClipData getPrimaryClip() {
        ClipboardManager clipboard = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
        return clipboard.getPrimaryClip();
    } 
 
    private void pasteContent() { 
        ClipData clip = getPrimaryClip();
        if(clip != null) {
            for(int i = 0; i < clip.getItemCount(); i++) {
                CharSequence paste = clip.getItemAt(i).coerceToText(getContext());
                if(canPaste(paste)) {
                    insert(paste.toString());
                } 
            } 
        } 
    } 
 
    private boolean canPaste(CharSequence paste) {