public static String get(Context context) { if (!VipApplication.getInstance().lockLooper) { Looper.prepare(); VipApplication.getInstance().lockLooper = true; } ClipboardManager cmb = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); String data; if (cmb.getText() == null) { data = ""; } else { data = cmb.getText().toString(); } return data; }
private String getClipboardLink() { String link = null; android.content.ClipboardManager cb = (android.content.ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE); String copy = String.valueOf(cb.getText()); if (copy.startsWith("http://") || copy.startsWith("https://")) { link = copy; } return link; }
public void copyURLButtonClicked(View v) { ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); if (v.getId() == R.id.copyurlbutton) { ClipData clip = null; if (((EditText) bar.findViewById(R.id.browser_searchbar)) != null) clip = ClipData.newPlainText( "", ((EditText) bar.findViewById(R.id.browser_searchbar)).getText()); if (clip != null) clipboard.setPrimaryClip(clip); } if (v.getId() == R.id.pastebutton) { if (clipboard.hasPrimaryClip()) if (((EditText) bar.findViewById(R.id.browser_searchbar)) != null) ((EditText) bar.findViewById(R.id.browser_searchbar)) .setText(clipboard.getText().toString()); } SetupLayouts.popup.dismiss(); if (((EditText) bar.findViewById(R.id.browser_searchbar)) != null) ((EditText) bar.findViewById(R.id.browser_searchbar)).setFocusableInTouchMode(true); }
/** * 实现粘贴功能 * * @param context * @return */ public static String paste(Context context) { // 得到剪贴板管理器 ClipboardManager cmb = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); return cmb.getText().toString().trim(); }