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

/**
 * A helper to copy the text to the clipboard.
 *
 * @param context//from  w  w  w  . ja  va 2s. co m
 * @param text A text to copy.
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static void copyText(Context context, String text) {
    final ClipboardManager clipboard = getClipboard(context);
    clipboard.setPrimaryClip(ClipData.newPlainText("Copied Text", text));
}

From source file:Main.java

public static void copy(Context context, String content) {
    ClipboardManager cmb = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    cmb.setPrimaryClip(ClipData.newPlainText(null, content));
}

From source file:Main.java

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

From source file:Main.java

public static void copyToClipboard(String text) {
    ClipboardManager cbm = (ClipboardManager) mContex.getSystemService(Activity.CLIPBOARD_SERVICE);
    cbm.setPrimaryClip(ClipData.newPlainText(mContex.getPackageName(), text));
}

From source file:Main.java

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

From source file:Main.java

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

From source file:Main.java

public static void copyUri(Uri uri, Context context) {
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    clipboard.setPrimaryClip(ClipData.newUri(context.getContentResolver(), "uri", uri));
}

From source file:Main.java

public static void copyToClipboard(final Context context, final String text) {
    final ClipboardManager cbm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    cbm.setPrimaryClip(ClipData.newPlainText(context.getPackageName(), text));
}

From source file:Main.java

public static void copyToClipBoard(Context context, String text, String success) {
    ClipData clipData = ClipData.newPlainText("keep_nice", text);
    ClipboardManager manager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    manager.setPrimaryClip(clipData);
    Toast.makeText(context, success, Toast.LENGTH_SHORT).show();
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static void copyToClipboard(Context context, String text) {
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    clipboard.setPrimaryClip(ClipData.newPlainText(null, text));
}