copy From Edit via Clipboard - Android android.content

Android examples for android.content:Clipboard

Description

copy From Edit via Clipboard

Demo Code

import android.content.ClipData;
import android.content.Context;
import android.os.Build;

public class Main{

    /**/* w ww  .ja  v  a 2  s .  c  o  m*/
     * 
     * @param context
     * @param label User-visible label for the clip data.
     * @param text The actual text in the clip.
     */
    public static void copyFromEdit(Context context, CharSequence label,
            CharSequence text) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            ((android.content.ClipboardManager) context
                    .getSystemService(Context.CLIPBOARD_SERVICE))
                    .setPrimaryClip(ClipData.newPlainText(label, text));
            return;
        }

        ((android.text.ClipboardManager) context
                .getSystemService(Context.CLIPBOARD_SERVICE)).setText(text);
    }

}

Related Tutorials