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)