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)