List of usage examples for android.content ClipboardManager getPrimaryClipDescription
public @Nullable ClipDescription getPrimaryClipDescription()
From source file:Main.java
private static boolean hasText(ClipboardManager clipboardManager, ClipData clipData) { final ClipDescription description = clipboardManager.getPrimaryClipDescription(); return clipData != null && description != null && description.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN); }
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
/** * Get text from Clipboard//from w ww . j a va 2 s. co m * * @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; }
From source file:Main.java
/** * Get intent from Clipboard/* w w w . ja v a 2s . 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//from www .j a va 2s . c om * * @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
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 {/* w w w . jav a 2s.c o m*/ //noinspection deprecation return cm.hasText(); } }
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 {// ww w. j a v a2 s.c o m return ""; } } else { //noinspection deprecation return cm.getText(); } }
From source file:org.ttrssreader.utils.Utils.java
public static String getTextFromClipboard(Context context) { // New Clipboard API ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); if (clipboard.hasPrimaryClip()) { if (!clipboard.getPrimaryClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) return null; ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0); CharSequence chars = item.getText(); if (chars != null && chars.length() > 0) { return chars.toString(); } else {//from w ww .j av a 2 s. c o m Uri pasteUri = item.getUri(); if (pasteUri != null) { return pasteUri.toString(); } } } return null; }
From source file:com.coloreight.plugin.clipboard.Clipboard.java
public void paste(final CallbackContext callbackContext) { cordova.getActivity().runOnUiThread(new Runnable() { public void run() { ClipboardManager clipboard = (ClipboardManager) cordova.getActivity() .getSystemService(Context.CLIPBOARD_SERVICE); if (!clipboard.getPrimaryClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.NO_RESULT)); }//from w ww.jav a 2 s . c om try { ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0); String text = item.getText().toString(); callbackContext.success(text); } catch (Exception e) { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, e.toString())); } } }); }
From source file:de.syss.MifareClassicTool.Common.java
/** * Get the content of the Android clipboard (if it is plain text). * @param context Context of the SystemService * @return The content of the Android clipboard. On error * (clipboard empty, clipboard content not plain text, etc.) null will * be returned.//from w ww. j a v a 2 s .c o m */ @SuppressLint("NewApi") @SuppressWarnings("deprecation") public static String getFromClipboard(Context context) { if (Build.VERSION.SDK_INT >= 11) { // Android API level 11+. android.content.ClipboardManager clipboard = (android.content.ClipboardManager) context .getSystemService(Context.CLIPBOARD_SERVICE); if (clipboard.getPrimaryClip() != null && clipboard.getPrimaryClip().getItemCount() > 0 && clipboard .getPrimaryClipDescription().hasMimeType(android.content.ClipDescription.MIMETYPE_TEXT_PLAIN)) { return clipboard.getPrimaryClip().getItemAt(0).getText().toString(); } } else { // Android API level 10. android.text.ClipboardManager clipboard = (android.text.ClipboardManager) context .getSystemService(Context.CLIPBOARD_SERVICE); if (clipboard.hasText()) { return clipboard.getText().toString(); } } // Error. return null; }