Example usage for android.content ClipboardManager setPrimaryClip

List of usage examples for android.content ClipboardManager setPrimaryClip

Introduction

In this page you can find the example usage for android.content ClipboardManager setPrimaryClip.

Prototype

public void setPrimaryClip(@NonNull ClipData clip) 

Source Link

Document

Sets the current primary clip on the clipboard.

Usage

From source file:Main.java

/**
 * This will copy text to the device's clipboard.
 *
 * @param context an application or activity context
 * @param text the string to be copied to the clipboard
 * @param description a user-visible label for the copied text
 *//*from   w ww .j  a va 2  s  .  c o  m*/
@TargetApi(VERSION_CODES.HONEYCOMB)
public static void copyText(Context context, String text, String description) {
    if (IS_AT_LEAST_HC) {
        ClipData clip = ClipData.newPlainText(description, text);
        ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
        clipboard.setPrimaryClip(clip);
    } else {
        android.text.ClipboardManager cm = (android.text.ClipboardManager) context
                .getSystemService(Context.CLIPBOARD_SERVICE);
        cm.setText(text);
    }
}

From source file:Main.java

public static void cleanUpClipboard(Context context) {
    ClipboardManager cbm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData data = ClipData.newPlainText("", "");
    cbm.setPrimaryClip(data);
}

From source file:Main.java

public static void copy2clipboard(Context context, String text) {
    ClipboardManager cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText("clip", text);
    cm.setPrimaryClip(clip);
}

From source file:Main.java

public static boolean setText(final Context context, final CharSequence text) {
    if (context == null)
        return false;
    final ClipboardManager clipboardManager = (ClipboardManager) context
            .getSystemService(Context.CLIPBOARD_SERVICE);
    clipboardManager.setPrimaryClip(ClipData.newPlainText(text, text));
    return true;//  www .j a  va 2 s. c o  m
}

From source file:Main.java

public static void copyToClipboard(Context context, String text) {
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText("copy", text);
    clipboard.setPrimaryClip(clip);
}

From source file:Main.java

public static void copyIntoClipboard(String label, String content, Context context) {
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText(label, content);
    clipboard.setPrimaryClip(clip);
}

From source file:Main.java

public static void copyText(Context context, String text) {
    ClipboardManager cmbName = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clipDataName = ClipData.newPlainText(null, text);
    cmbName.setPrimaryClip(clipDataName);
}

From source file:Main.java

public static void copyText(Context context, String text) {
    ClipboardManager manager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clipData = ClipData.newPlainText("GankLy_copy", text);
    manager.setPrimaryClip(clipData);
}

From source file:Main.java

public static void copyToClipBoard(Context context, String key, String value) {
    ClipboardManager clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clipData = ClipData.newPlainText(key, value);
    clipboardManager.setPrimaryClip(clipData);
}

From source file:Main.java

public static boolean copyStringToClipboard(Context context, String label, String src) {
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText(label, src);
    clipboard.setPrimaryClip(clip);
    return true;/*from  w  w  w.  ja  v  a2  s.c o  m*/
}