Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

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 copyText(Context context, String text) {
        ClipboardManager cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            ClipData clip = ClipData.newPlainText("", text);
            cm.setPrimaryClip(clip);
        } else {
            //noinspection deprecation
            cm.setText(text);
        }
    }
}