Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to copy text to ClipBoard

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 47
    Comment on it

    If you are looking to copy the text from android widgets to clipboard, you can use the below code

    TextView contentTextBox=(TextView) findViewById(R.id.tv_content); //get textview  from which you want to copy the content
    String textToCopy = contentTextBox.getText().toString();
      if(textToCopy.length() != 0)
        {
           if(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) // check sdk version
              {
                 android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                 clipboard.setText(textToCopy);
                 Toast.makeText(getApplicationContext(), "Copied to Clipboard", Toast.LENGTH_SHORT).show();
              }
           else 
              {
                android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemServic(Context.CLIPBOARD_SERVICE);
                android.content.ClipData clipData = android.content.ClipData.newPlainText("Clip",textToCopy);
                Toast.makeText(getApplicationContext(), "Copied to Clipboard", Toast.LENGTH_SHORT).show();
                clipboard.setPrimaryClip(clipData);
               }
        }
       else
         {
          Toast.makeText(getApplicationContext(), "Empty Selection", Toast.LENGTH_SHORT).show();
         }
    

 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: