Android gives us the facility to copy and paste the data by providing clipboard.
We can copy text, binary stream, images or other data.
Android provides ClipboardManager to handle all this.
We have to instantiate the object of ClipboardManager by using getSystemSerice() like this.
ClipboardManager cbm;
cbm = (ClipboardManager)getSystemService(CLIPBOARD_SERVICE);
Copy data:
ClipData cd;
String text = "clipboard message";
cd = ClipData.newPlainText("text", text);
cbm.setPrimaryClip(cd);
ClipData can use three types of data:
1. Text
2. URI
3. Intent
Paste data:
ClipData abc = cbm.getPrimaryClip();
ClipData.Item clipItem = abc.getItemAt(0);
String text = clipItem.getText().toString();
0 Comment(s)