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

@SuppressWarnings("deprecation")
public static boolean setClipboard(Context context, String text) {
    android.text.ClipboardManager clipboard = (android.text.ClipboardManager) context
            .getSystemService(Context.CLIPBOARD_SERVICE);
    clipboard.setText(text);/*from ww w  .  ja va 2s. c  o  m*/
    return true;
}

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();
    }/*w w  w  . jav a  2  s  . c  o m*/
    return null;
}

From source file:Main.java

public static void putTextIntoClipboard(Context context, String text) {
    ClipboardManager clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clipData = ClipData.newPlainText("copy text", text);
    clipboardManager.setPrimaryClip(clipData);
}

From source file:Main.java

public static void copyUri(Uri uri, Context context) {
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    clipboard.setPrimaryClip(ClipData.newUri(context.getContentResolver(), "uri", uri));
}

From source file:Main.java

public static void setClip(Context context, CharSequence text) {
    ((ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE))
            .setPrimaryClip(ClipData.newPlainText("", text));
}

From source file:Main.java

/**
 * //from   ww  w . j a  v a2 s.c  o m
 * @param context
 * @param text
 */
public static void copy(Context context, String text) {
    android.text.ClipboardManager cmb = (android.text.ClipboardManager) context
            .getSystemService(Context.CLIPBOARD_SERVICE);
    cmb.setText(text);
}

From source file:Main.java

public static void copy(Context context, String content) {
    ClipboardManager cmb = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    cmb.setPrimaryClip(ClipData.newPlainText(null, content));
}

From source file:Main.java

private static boolean hasText(Context c) {
    ClipboardManager clipboard = (ClipboardManager) c.getSystemService(Context.CLIPBOARD_SERVICE);

    return clipboard.hasPrimaryClip()
            && clipboard.getPrimaryClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN);
}

From source file:Main.java

public static void init(Application application) {
    sClipboardManager = (ClipboardManager) application.getSystemService(Context.CLIPBOARD_SERVICE);
}

From source file:Main.java

@SuppressWarnings("deprecation")
public static String getText4Clipboard(Context context) {
    ClipboardManager cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    if (cm != null && cm.getText() != null) {
        return cm.getText().toString();
    }// w ww . j a va2s .  co  m
    return "";
}