copy plain text To Clipboard - Android android.content

Android examples for android.content:Clipboard

Description

copy plain text To Clipboard

Demo Code

import android.annotation.TargetApi;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.os.Build;

public class Main{

    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    public static void copyToClipboard(Context context, String text) {
        ClipboardManager clipboard = (ClipboardManager) context
                .getSystemService(Context.CLIPBOARD_SERVICE);
        clipboard.setPrimaryClip(ClipData.newPlainText(null, text));
    }/*from w  w  w.  java 2s.  co  m*/

}

Related Tutorials