Java tutorial
//package com.java2s; /* * Tint Browser for Android * * Copyright (C) 2012 - to infinity and beyond J. Devauchelle and contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * version 3 as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ import android.content.ClipData; import android.content.Context; import android.content.ClipboardManager; import android.widget.Toast; public class Main { /** * Copy a text to the clipboard. * @param context The current context. * @param text The text to copy. * @param toastMessage The message to show in a Toast notification. If empty or null, does not display notification. */ public static void copyTextToClipboard(Context context, String text, String toastMessage) { ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setPrimaryClip(ClipData.newPlainText(text, text)); if ((toastMessage != null) && (toastMessage.length() > 0)) { Toast.makeText(context, toastMessage, Toast.LENGTH_SHORT).show(); } } }