List of usage examples for android.content ClipboardManager setPrimaryClip
public void setPrimaryClip(@NonNull ClipData clip)
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 copy(Activity activity, String tag, String text) { ClipboardManager clipboard = (ClipboardManager) activity.getSystemService(activity.CLIPBOARD_SERVICE); ClipData clip = android.content.ClipData.newPlainText(tag, text); clipboard.setPrimaryClip(clip); }
From source file:Main.java
/** * copy plain text to clip board//from w w w . ja v a 2 s. c om * * @param context * @param tag * @param text * @param toastText may null, no toast at all */ public static void copy2ClipBoard(Context context, String tag, String text, String toastText) { ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText(tag, text); clipboard.setPrimaryClip(clip); if (toastText != null) { Toast.makeText(context, toastText, Toast.LENGTH_SHORT).show(); } }
From source file:Main.java
/** * Copies text./* w w w.j a v a 2 s . com*/ * * @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
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); } else {//from w ww. j a v a 2 s.c o m 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 copyToClipboard(Context context, String label, String string, int toastMessageId) { ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText(label, string); clipboard.setPrimaryClip(clip); if (toastMessageId > 0) { Toast.makeText(context, toastMessageId, Toast.LENGTH_LONG).show(); }/*from w ww.j ava2 s . co m*/ }
From source file:Main.java
public static void copy(Context context, String str) { ClipboardManager clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); String lable = str;/*from w w w . jav a 2s.co m*/ if (str.length() > 10) lable = str.substring(0, 10); clipboardManager.setPrimaryClip(ClipData.newPlainText(lable, str)); }
From source file:Main.java
public static void setClipBoard(final Context context, final String msg, Handler handler) { Runnable updater = new Runnable() { public void run() { ClipboardManager clip = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); ClipData data = ClipData.newPlainText("Remoteroid_Clip", msg); clip.setPrimaryClip(data); }//from www . j a v a2s .c o m }; handler.post(updater); }
From source file:Main.java
/** * Copy tags to clipboard as multi-line text in the form * key1=value1// ww w . ja va 2 s. c om * key2=value2 * ..... * @param tags */ @SuppressWarnings("deprecation") @SuppressLint("NewApi") public static void copyTags(Context ctx, Map<String, String> tags) { StringBuffer tagsAsText = new StringBuffer(); for (String key : tags.keySet()) { tagsAsText.append(key + "=" + tags.get(key) + "\n"); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { ClipboardManager clipboard = (ClipboardManager) ctx.getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("OSM Tags", tagsAsText.toString()); clipboard.setPrimaryClip(clip); } else { android.text.ClipboardManager oldClipboard = (android.text.ClipboardManager) ctx .getSystemService(Context.CLIPBOARD_SERVICE); oldClipboard.setText(tagsAsText.toString()); } }
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); } else {//from w ww . j a va2 s . com //noinspection deprecation cm.setText(text); } }