Android Clipboard Copy copyToClipboard(Context context, String lable, String text)

Here you can find the source of copyToClipboard(Context context, String lable, String text)

Description

Set text as new main clip in the clipboard.

Parameter

Parameter Description
context the application Context
lable the label given to the
text the text for the clipboard

Return

Returns true if operation has succeeded.

Declaration

public static boolean copyToClipboard(Context context, String lable,
        String text) 

Method Source Code

//package com.java2s;

import android.content.Context;
import android.os.Looper;

public class Main {
    /**/* w  w  w  .  j  a v  a  2  s.co  m*/
     * Set text as new main clip in the clipboard.
     * @param context the application {@link Context}
     * @param lable the label given to the
     * @param text the text for the clipboard
     * @return Returns true if operation has succeeded.
     */
    public static boolean copyToClipboard(Context context, String lable,
            String text) {
        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;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
}

Related

  1. onCopy(Context context, String content)
  2. copyToClipboard(Context context, String label, String string, int toastMessageId)
  3. copyToClipboard(Context context, String lable, String text)
  4. set(Context context, String value)
  5. setClipboard(Context context, String text)
  6. setText(final Context context, final CharSequence text)
  7. setText(final Context context, final CharSequence text)