Java tutorial
//package com.java2s; //License from project: Open Source License import android.annotation.TargetApi; import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; import android.os.Build; public class Main { /** * A helper to copy the text to the clipboard. * * @param context * @param text A text to copy. */ @TargetApi(Build.VERSION_CODES.HONEYCOMB) public static void copyText(Context context, String text) { final ClipboardManager clipboard = getClipboard(context); clipboard.setPrimaryClip(ClipData.newPlainText("Copied Text", text)); } private static ClipboardManager getClipboard(Context context) { return (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); } }