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

public static void copyToClipBoard(Context context, String text, String success) {
    ClipData clipData = ClipData.newPlainText("gank", 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

/***** API>=11 *****/
@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));
}

From source file:Main.java

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

From source file:Main.java

public static void copyToClipBoard(Context context, String text, String success) {
    ClipData clipData = ClipData.newPlainText("meizhi_copy", 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

public static void addToClipboard(Context ctx, String text) {
    ClipboardManager clipboardManager = (ClipboardManager) ctx.getSystemService(Context.CLIPBOARD_SERVICE);
    clipboardManager.setPrimaryClip(ClipData.newPlainText(CLIPBOARD_LABEL, text));
}

From source file:Main.java

/**
 * Copy a text to the clipboard.// w  w w  .ja  va  2 s  .c o m
 * @param context The current context.
 * @param text The text to copy.
 * @param toastMessage The message to show in a Toast notification. If empty or null, does not display notification.
 */
public static void copyTextToClipboard(Context context, String text, String toastMessage) {
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    clipboard.setPrimaryClip(ClipData.newPlainText(text, text));

    if ((toastMessage != null) && (toastMessage.length() > 0)) {
        Toast.makeText(context, toastMessage, Toast.LENGTH_SHORT).show();
    }
}

From source file:Main.java

/**
 * Copy a text to the clipboard./*  w  w w  .ja va  2s .c o m*/
 * 
 * @param context
 *            The current context.
 * @param text
 *            The text to copy.
 * @param toastMessage
 *            The message to show in a Toast notification. If empty or null, does not display notification.
 */
public static void copyTextToClipboard(Context context, String text, String toastMessage) {
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE);
    clipboard.setPrimaryClip(ClipData.newPlainText(text, text));

    if ((toastMessage != null) && (toastMessage.length() > 0)) {
        Toast.makeText(context, toastMessage, Toast.LENGTH_SHORT).show();
    }
}

From source file:Main.java

/**
 * Copy text to Clipboard/*from   ww w .  j av  a  2 s.c  om*/
 *
 * @param context
 * @param text
 */
public static void copy(Context context, String text) {
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    clipboard.setPrimaryClip(ClipData.newPlainText(null, text));
}

From source file:Main.java

/**
 * Copy uri to Clipboard/* w  w w  .j  av a  2s.  c  om*/
 *
 * @param context
 * @param uri
 */
public static void copy(Context context, Uri uri) {
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    clipboard.setPrimaryClip(ClipData.newUri(context.getContentResolver(), null, uri));
}

From source file:Main.java

/**
 * Copy intent to Clipboard//from  w  ww.ja va2  s.  c  o m
 *
 * @param context
 * @param intent
 */
public static void copy(Context context, Intent intent) {
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    clipboard.setPrimaryClip(ClipData.newIntent(null, intent));
}