Here you can find the source of copyToClipboard(Context context, String lable, String text)
Parameter | Description |
---|---|
context | the application Context |
lable | the label given to the |
text | the text for the clipboard |
public static boolean copyToClipboard(Context context, String lable, String text)
//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; } } }