Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Copy to clipboard programatically

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 297
    Comment on it

    Clipboard is just a type of register where you can save some temporary data. you can't store data permanently here so its nice place to store temp data.

    For this you have to create a edittext from where you will copy text and then you have to set that text on clipboard manager like this :

    @Override
    public void onClick(View arg0) {
    String copyText = edittext.getText().toString().trim();
    if(copyText.length() > 0) {
    if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
    android.text.ClipboardManager clipboardManager = (android.text.ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    clipboardManager.setText(copyText);
    } else {
    android.content.ClipboardManager clipboardManager = (android.content.ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText("Copied text", copyText);
    clipboardManager.setPrimaryClip(clip);
    }
    }
    }
    });
    }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: