copy text To Clipboard - Android android.content

Android examples for android.content:ClipboardManager

Description

copy text To Clipboard

Demo Code

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.text.Editable;
import android.text.SpannedString;
import android.util.Pair;

public class Main{

    /**//from   w  w  w.  ja va 2s .  c  o m
     * Copies the text to the clipboard
     * @param text
     */
    public static void copyToClipboard(Context context, String text) {
        ClipboardManager clipboard = (ClipboardManager) context
                .getSystemService(Context.CLIPBOARD_SERVICE);
        ClipData clip = ClipData.newPlainText("simple text", text);
        clipboard.setPrimaryClip(clip);
    }

}

Related Tutorials