Java Code Examples for android.content.ClipboardManager#getText()

The following examples show how to use android.content.ClipboardManager#getText() . 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 File: ws_Main3Activity.java    From styT with Apache License 2.0 6 votes vote down vote up
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 File: x5_MainActivity.java    From stynico with MIT License 6 votes vote down vote up
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 File: ClipboardUtils.java    From AdBlockedWebView-Android with MIT License 6 votes vote down vote up
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 File: PlansManagerActivity.java    From ankihelper with GNU General Public License v3.0 5 votes vote down vote up
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 File: FastEdit.java    From fastedit with Apache License 2.0 4 votes vote down vote up
public void paste() {
    ClipboardManager cm = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
    CharSequence text = cm.getText();
    insert(text.toString());
}