Android examples for android.content:Clipboard
get Text from Clipboard by index
import android.annotation.TargetApi; import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; import android.os.Build; import android.text.TextUtils; public class Main{ @TargetApi(Build.VERSION_CODES.HONEYCOMB) public static String getText(Context context, int index) { ClipboardManager clipboard = (ClipboardManager) context .getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = clipboard.getPrimaryClip(); if (clip != null && clip.getItemCount() > index) { return String.valueOf(clip.getItemAt(0).coerceToText(context)); }/* www. j a v a 2 s.c o m*/ return null; } @TargetApi(Build.VERSION_CODES.HONEYCOMB) public static int getItemCount(Context context) { ClipboardManager clipboard = (ClipboardManager) context .getSystemService(Context.CLIPBOARD_SERVICE); ClipData data = clipboard.getPrimaryClip(); return data.getItemCount(); } }