Android Utililty Methods Clipboard Copy

List of utility methods to do Clipboard Copy

Description

The list of methods to do Clipboard Copy are organized into topic(s).

Method

voidonCopy(Context context, String content)
on Copy
ClipboardManager cmb = (ClipboardManager) context
        .getSystemService(Context.CLIPBOARD_SERVICE);
cmb.setText(content.trim());
voidcopyToClipboard(Context context, String label, String string, int toastMessageId)
copy To Clipboard
ClipboardManager clipboard = (ClipboardManager) context
        .getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText(label, string);
clipboard.setPrimaryClip(clip);
if (toastMessageId > 0) {
    Toast.makeText(context, toastMessageId, Toast.LENGTH_LONG)
            .show();
booleancopyToClipboard(Context context, String lable, String text)
copy To Clipboard
try {
    android.content.ClipboardManager clipboard = (android.content.ClipboardManager) context
            .getSystemService(Context.CLIPBOARD_SERVICE);
    android.content.ClipData clip = android.content.ClipData
            .newPlainText(lable, text);
    clipboard.setPrimaryClip(clip);
    return true;
} catch (Exception e) {
...
booleancopyToClipboard(Context context, String lable, String text)
Set text as new main clip in the clipboard.
Looper.prepare();
try {
    android.content.ClipboardManager clipboard = (android.content.ClipboardManager) context
            .getSystemService(Context.CLIPBOARD_SERVICE);
    android.content.ClipData clip = android.content.ClipData
            .newPlainText(lable, text);
    clipboard.setPrimaryClip(clip);
    return true;
...
voidset(Context context, String value)
set
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
    ClipboardManager clipboard = (ClipboardManager) context
            .getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clipData = ClipData.newPlainText("text", value);
    clipboard.setPrimaryClip(clipData);
} else {
    ClipboardManager clipboard = (ClipboardManager) context
            .getSystemService(Context.CLIPBOARD_SERVICE);
...
booleansetClipboard(Context context, String text)
set Clipboard
android.text.ClipboardManager clipboard = (android.text.ClipboardManager) context
        .getSystemService(Context.CLIPBOARD_SERVICE);
clipboard.setText(text);
return true;
booleansetText(final Context context, final CharSequence text)
set Text
if (context == null)
    return false;
((ClipboardManager) context
        .getSystemService(Context.CLIPBOARD_SERVICE)).setText(text);
return true;
booleansetText(final Context context, final CharSequence text)
set Text
if (context == null)
    return false;
((ClipboardManager) context
        .getSystemService(Context.CLIPBOARD_SERVICE))
        .setText(text != null ? text : "");
return true;
voidcopy(Context context, String content)
copy
ClipboardManager cmb = (ClipboardManager) context
        .getSystemService(Context.CLIPBOARD_SERVICE);
cmb.setText(content.trim());
voidcopyText(Context context, String text)
copy Text
android.text.ClipboardManager cm = (android.text.ClipboardManager) context
        .getSystemService(Context.CLIPBOARD_SERVICE);
cm.setText(text);