Java Code Examples for android.content.ClipboardManager#getText()
The following examples show how to use
android.content.ClipboardManager#getText() .
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: styT File: ws_Main3Activity.java License: Apache License 2.0 | 6 votes |
private String getClipboardText() { ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); String text = ""; try { if (clipboard != null && clipboard.hasText()) { CharSequence tmpText = clipboard.getText(); clipboard.setText(tmpText); if (tmpText != null && tmpText.length() > 0) { text = tmpText.toString().trim(); } } } catch (Exception e) { e.printStackTrace(); text = ""; } return text; }
Example 2
Source Project: stynico File: x5_MainActivity.java License: MIT License | 6 votes |
private String getClipboardText() { ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); String text = ""; try { if (clipboard != null && clipboard.hasText()) { CharSequence tmpText = clipboard.getText(); clipboard.setText(tmpText); if (tmpText != null && tmpText.length() > 0) { text = tmpText.toString().trim(); } } } catch (Exception e) { e.printStackTrace(); text = ""; } return text; }
Example 3
Source Project: AdBlockedWebView-Android File: ClipboardUtils.java License: MIT License | 6 votes |
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 { return ""; } } else { //noinspection deprecation return cm.getText(); } }
Example 4
Source Project: ankihelper File: PlansManagerActivity.java License: GNU General Public License v3.0 | 5 votes |
private void importPlans() { ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); if(clipboard.hasPrimaryClip()){ if(clipboard.getText()!=null){ String plansString = clipboard.getText().toString(); processPlanString(plansString); } }else{ Toast.makeText(this, "剪贴板为空!", Toast.LENGTH_SHORT).show(); } }
Example 5
Source Project: fastedit File: FastEdit.java License: Apache License 2.0 | 4 votes |
public void paste() { ClipboardManager cm = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE); CharSequence text = cm.getText(); insert(text.toString()); }