1

I want to copy some text in temprory memory :

TextView tv = (int)findViewById(R.id.txt);
String str = tv.getText().toString();

now how an I copy str in clipboard ???

Erfan Bagheri
  • 638
  • 1
  • 8
  • 16

3 Answers3

7

Use ClipboardManager

int sdk = android.os.Build.VERSION.SDK_INT;
if(sdk < android.os.Build.VERSION_CODES.HONEYCOMB) {
    android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    clipboard.setText("text to clip");
} else {
    android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); 
    android.content.ClipData clip = android.content.ClipData.newPlainText("text label","text to clip");
    clipboard.setPrimaryClip(clip);
}
Nirav Ranpara
  • 13,753
  • 3
  • 39
  • 54
0

you have to use ClipboardManager.

here the doc.

you have to call setPrimaryClip with a ClipData

Blackbelt
  • 156,034
  • 29
  • 297
  • 305
0

You may need ClipboardManager and perhaps this could help.

Community
  • 1
  • 1
kiwi
  • 487
  • 1
  • 4
  • 16