Try Get Text From Clipboard - Android android.content

Android examples for android.content:Clipboard

Description

Try Get Text From Clipboard

Demo Code

import android.content.Context;
import android.text.ClipboardManager;

public class Main{

    public static boolean TryGetTextFromClipboard(Context context,
            Holder<String> text) {
        try {/*from www. ja  v a 2 s . c  o m*/
            ClipboardManager clipboard = (ClipboardManager) context
                    .getSystemService(Context.CLIPBOARD_SERVICE);
            if (clipboard != null) {
                CharSequence clipboardText = clipboard.getText();
                if (clipboardText != null && clipboardText.length() > 0) {
                    String textResult = clipboardText.toString();
                    if (!textResult.startsWith("intent")) {
                        text.value = textResult;
                        return true;
                    }
                }
            }
        } catch (Exception e) {

        }
        return false;
    }

}

Related Tutorials