copy To Clipboard as primary clip - Android Android OS

Android examples for Android OS:Clipboard

Description

copy To Clipboard as primary clip

Demo Code


//package com.java2s;

import android.content.Context;

public class Main {
    public static boolean copyToClipboard(Context context, String lable,
            String text) {//from   w w w . j a va 2 s.  co  m
        try {
            android.content.ClipboardManager clipboard = (android.content.ClipboardManager) context
                    .getSystemService(Context.CLIPBOARD_SERVICE);
            android.content.ClipData clip = android.content.ClipData
                    .newPlainText(lable, text);
            clipboard.setPrimaryClip(clip);

            return true;
        } catch (Exception e) {
            return false;
        }
    }
}

Related Tutorials