Example usage for android.content ClipData getItemAt

List of usage examples for android.content ClipData getItemAt

Introduction

In this page you can find the example usage for android.content ClipData getItemAt.

Prototype

public Item getItemAt(int index) 

Source Link

Document

Return a single item inside of the clip data.

Usage

From source file:Main.java

@NonNull
public static String paste(Context context) {
    ClipboardManager manager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clipData = manager.getPrimaryClip();
    ClipData.Item item = clipData.getItemAt(0);
    return item.getText().toString();
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static String getText(Context context) {
    final ClipboardManager clipboard = getClipboard(context);
    final ClipData clipData = clipboard.getPrimaryClip();

    return clipData.getItemAt(0).getText().toString();
}

From source file:Main.java

public static CharSequence getText(Context context) {
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = clipboard.getPrimaryClip();
    if (clip != null && clip.getItemCount() > 0) {
        return clip.getItemAt(0).coerceToText(context);
    }//from  w w w . java 2s.  com
    return null;
}

From source file:Main.java

public static Uri getUri(Context context) {
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = clipboard.getPrimaryClip();
    if (clip != null && clip.getItemCount() > 0) {
        return clip.getItemAt(0).getUri();
    }//ww w .j  a  v  a2 s .c om
    return null;
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static String getLatestText(Context context) {
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = clipboard.getPrimaryClip();
    if (clip != null && clip.getItemCount() > 0) {
        return String.valueOf(clip.getItemAt(0).coerceToText(context));
    }//from  w  w  w.  j av  a 2  s.  co  m
    return null;
}

From source file:Main.java

@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));
    }//  ww  w . j a  va  2 s. c o  m
    return null;
}

From source file:Main.java

/**
 * Get intent from Clipboard/*from w ww  . j a v a 2  s.co  m*/
 *
 * @param context
 * @return
 */
public static Intent getIntent(Context context) {
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    if (clipboard.hasPrimaryClip()
            && clipboard.getPrimaryClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_INTENT)) {
        ClipData clip = clipboard.getPrimaryClip();
        if (clip != null && clip.getItemCount() > 0) {
            return clip.getItemAt(0).getIntent();
        }
    }
    return null;
}

From source file:Main.java

/**
 * Get uri from Clipboard//ww w .j a  v  a2  s . c  o m
 *
 * @param context
 * @return
 */
public static Uri getUri(Context context) {
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    if (clipboard.hasPrimaryClip()
            && clipboard.getPrimaryClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_URILIST)) {
        ClipData clip = clipboard.getPrimaryClip();
        if (clip != null && clip.getItemCount() > 0) {
            return clip.getItemAt(0).getUri();
        }
    }
    return null;
}

From source file:Main.java

private static String getClipText(Context context) {
    String text = "";
    ClipboardManager cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clipData = cm.getPrimaryClip();
    if (clipData != null) {
        if (clipData.getItemCount() > 0) {
            ClipData.Item item = clipData.getItemAt(0);
            text = item.getText().toString();
        }//from   w  w  w  .j a va  2s . com
    }

    return text;
}

From source file:Main.java

/**
 * Get text from Clipboard//  w w  w  .j  ava2s .  com
 *
 * @param context
 * @return
 */
public static String getText(Context context) {
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    if (clipboard.hasPrimaryClip()
            && clipboard.getPrimaryClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
        ClipData clip = clipboard.getPrimaryClip();
        if (clip != null && clip.getItemCount() > 0) {
            return String.valueOf(clip.getItemAt(0).coerceToText(context));
        }
    }
    return null;
}