Java tutorial
//package com.java2s; /* * The MIT License (MIT) * Copyright (c) 2014 longkai * The software shall be used for good, not evil. */ import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; import android.widget.Toast; public class Main { /** * copy plain text to clip board * * @param context * @param tag * @param text * @param toastText may null, no toast at all */ public static void copy2ClipBoard(Context context, String tag, String text, String toastText) { ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText(tag, text); clipboard.setPrimaryClip(clip); if (toastText != null) { Toast.makeText(context, toastText, Toast.LENGTH_SHORT).show(); } } }