List of usage examples for android.content Context CLIPBOARD_SERVICE
String CLIPBOARD_SERVICE
To view the source code for android.content Context CLIPBOARD_SERVICE.
Click Source Link
From source file:Main.java
public static CharSequence getText(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(); if (clipData != null && description != null && description.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) { return clipData.getItemAt(0).getText(); } else {/*www .ja v a 2 s . c om*/ return ""; } } else { //noinspection deprecation return cm.getText(); } }
From source file:Main.java
public static String pasteString(Context context) { int currentapiVersion = android.os.Build.VERSION.SDK_INT; if (currentapiVersion >= android.os.Build.VERSION_CODES.HONEYCOMB) { android.content.ClipboardManager clipboard = (android.content.ClipboardManager) context .getSystemService(Context.CLIPBOARD_SERVICE); return clipboard.getText().toString().trim(); } else {//w w w . ja va2 s . co m android.text.ClipboardManager clipboard = (android.text.ClipboardManager) context .getSystemService(Context.CLIPBOARD_SERVICE); return clipboard.getText().toString(); } }
From source file:Main.java
/***** API>=11 *****/ @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
/** * Copies text./* w w w .ja v a2 s.c o m*/ * * @param text The actual text we want to copy. */ public static void copyText(Context context, CharSequence text) { ClipboardManager clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); ClipData clipData = ClipData.newPlainText("simple text", text); clipboardManager.setPrimaryClip(clipData); }
From source file:Main.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) public static void copyText(Context context, String text) { ClipboardManager cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { ClipData clip = ClipData.newPlainText("", text); cm.setPrimaryClip(clip);/* w w w .j a v a 2 s .c om*/ } else { //noinspection deprecation cm.setText(text); } }
From source file:Main.java
public static void clip(Context context, String text) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { android.text.ClipboardManager clipboardManager = (android.text.ClipboardManager) context .getSystemService(Context.CLIPBOARD_SERVICE); clipboardManager.setText(text);/*from w w w .j a va2 s . co m*/ } else { ClipboardManager clipboardManager = (ClipboardManager) context .getSystemService(Context.CLIPBOARD_SERVICE); clipboardManager.setPrimaryClip(ClipData.newPlainText("mq_content", text)); } }
From source file:Main.java
public static boolean copyToClipboard(Context context, String text) { try {// w ww.ja v a 2 s . c o m if (Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) { android.text.ClipboardManager clipboard = (android.text.ClipboardManager) context .getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setText(text); } else { android.content.ClipboardManager clipboard = (android.content.ClipboardManager) context .getSystemService(Context.CLIPBOARD_SERVICE); android.content.ClipData clip = android.content.ClipData.newPlainText("text", text); clipboard.setPrimaryClip(clip); } return true; } catch (Exception e) { return false; } }
From source file:Main.java
public static void copyToClipboard(Context context, String label, String content) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText(label, content); clipboard.setPrimaryClip(clip);/*from ww w. jav a 2 s . c o m*/ } else { android.text.ClipboardManager clipboard = (android.text.ClipboardManager) context .getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setText("text to clip"); } }
From source file:Main.java
public static void copyIntoClipboard(String label, String content, Context context) { ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText(label, content); clipboard.setPrimaryClip(clip);/*from www . ja v a2s . com*/ }
From source file:Main.java
private static void instance(Context context) { if (isNew()) { if (mNewCliboardManager == null) mNewCliboardManager = (android.content.ClipboardManager) context .getSystemService(Context.CLIPBOARD_SERVICE); } else {//from w ww .j ava 2s. c o m if (mClipboardManager == null) mClipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); } }