Java tutorial
//package com.java2s; //License from project: Open Source License import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; import android.os.Build; public class Main { private static ClipboardManager mClipboardManager; private static android.content.ClipboardManager mNewCliboardManager; public static void setText(Context context, CharSequence text) { if (isNew()) { instance(context); // Creates a new text clip to put on the clipboard ClipData clip = ClipData.newPlainText("simple text", text); // Set the clipboard's primary clip. mNewCliboardManager.setPrimaryClip(clip); } else { instance(context); mClipboardManager.setText(text); } } private static boolean isNew() { return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB; } private static void instance(Context context) { if (isNew()) { if (mNewCliboardManager == null) mNewCliboardManager = (android.content.ClipboardManager) context .getSystemService(Context.CLIPBOARD_SERVICE); } else { if (mClipboardManager == null) mClipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); } } }