Example usage for android.content Context CLIPBOARD_SERVICE

List of usage examples for android.content Context CLIPBOARD_SERVICE

Introduction

In this page you can find the example usage for android.content Context CLIPBOARD_SERVICE.

Prototype

String CLIPBOARD_SERVICE

To view the source code for android.content Context CLIPBOARD_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.content.ClipboardManager for accessing and modifying the contents of the global clipboard.

Usage

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();
        }// w  w w .j av  a  2  s  . com
    }

    return text;
}

From source file:Main.java

public static void copyToClipBoard(Context context, String copyText) {
    ClipData clipData = ClipData.newPlainText("codegank_copy", copyText);
    ClipboardManager manager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    manager.setPrimaryClip(clipData);//from   ww w.  jav  a 2s.  c  om
}

From source file:Main.java

@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();
}

From source file:Main.java

public static boolean hasText(Context context) {
    ClipboardManager cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        ClipDescription description = cm.getPrimaryClipDescription();
        ClipData clipData = cm.getPrimaryClip();
        return clipData != null && description != null
                && (description.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN));
    } else {/* ww  w  . jav  a  2s . c  o m*/
        //noinspection deprecation
        return cm.hasText();
    }
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static void copyToClipboard(Context context, String text) {
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    clipboard.setPrimaryClip(ClipData.newPlainText(null, text));
}

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));
    }// w  w w .  j  a  v  a  2s.c om
    return null;
}

From source file:Main.java

public static void copyToClipBoard(Context context, String text, String success) {
    ClipData clipData = ClipData.newPlainText("gank", text);
    ClipboardManager manager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    manager.setPrimaryClip(clipData);/*from ww  w.ja  v  a  2s .  com*/
    Toast.makeText(context, success, Toast.LENGTH_SHORT).show();
}

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));
    }//from   w w w  . j  a v  a  2s .c  om
    return null;
}

From source file:Main.java

public static void copyToClipBoard(Context context, String text, String success) {
    ClipData clipData = ClipData.newPlainText("keep_nice", text);
    ClipboardManager manager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    manager.setPrimaryClip(clipData);/*w  ww . j  a va  2 s.c  o  m*/
    Toast.makeText(context, success, Toast.LENGTH_SHORT).show();
}

From source file:Main.java

public static void getLatestTextSupport(Context context) {
    android.text.ClipboardManager clipboard = (android.text.ClipboardManager) context
            .getSystemService(Context.CLIPBOARD_SERVICE);
    clipboard.getText();//from ww w .  j a v  a  2  s  .  c o  m
}