copy Text, create ClipData - Android Android OS

Android examples for Android OS:Clipboard

Description

copy Text, create ClipData

Demo Code


//package com.java2s;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;

public class Main {
    public static void copyText(Context context, String text) {
        ClipData cd = ClipData.newPlainText(text, text);
        ClipboardManager cm = (ClipboardManager) context
                .getSystemService(Context.CLIPBOARD_SERVICE);
        cm.setPrimaryClip(cd);//from w ww  .  java 2 s .  co  m
    }
}

Related Tutorials