paste To Result via Clipboard - Android android.content

Android examples for android.content:Clipboard

Description

paste To Result via Clipboard

Demo Code

import android.content.ClipData;
import android.content.Context;
import android.os.Build;

public class Main{

    /**//from  w  ww .  j av a  2  s  .  c o  m
     * 
     * @param context
     * @return
     */
    public static CharSequence pasteToResult(Context context) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            ClipData clipData = ((android.content.ClipboardManager) context
                    .getSystemService(Context.CLIPBOARD_SERVICE))
                    .getPrimaryClip();
            if ((clipData == null) || (clipData.getItemCount() <= 0)) {
                return null;
            }

            ClipData.Item item = clipData.getItemAt(0);
            if (item == null) {
                return null;
            }
            return item.getText();
        }

        return ((android.text.ClipboardManager) context
                .getSystemService(Context.CLIPBOARD_SERVICE)).getText();
    }

}

Related Tutorials