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.app.Activity;

import android.content.Context;

import android.text.ClipboardManager;

import android.widget.Toast;

public class Main {
    /**
     * Copy a text to the clipboard.
     * @param context
     * @param text
     * @param toastMessage The message to show in a Toast notification. If empty or null, does not display notification.
     */
    public static void copyTextToClipboard(Context context, String text, String toastMessage) {
        ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE);
        clipboard.setText(text);

        if (toastMessage != null && toastMessage.length() > 0) {
            Toast.makeText(context, toastMessage, Toast.LENGTH_SHORT).show();
        }
    }
}