Example usage for android.content Context CLIPBOARD_SERVICE

List of usage examples for android.content Context CLIPBOARD_SERVICE

Introduction

In this page you can find the example usage for android.content Context CLIPBOARD_SERVICE.

Prototype

String CLIPBOARD_SERVICE

To view the source code for android.content Context CLIPBOARD_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.content.ClipboardManager for accessing and modifying the contents of the global clipboard.

Usage

From source file:com.codename1.impl.android.AndroidImplementation.java

/**
 * @inheritDoc//from   ww  w  .ja va  2  s . c o m
 */
public Object getPasteDataFromClipboard() {
    if (getContext() == null) {
        return null;
    }
    final Object[] response = new Object[1];
    runOnUiThreadAndBlock(new Runnable() {
        @Override
        public void run() {
            int sdk = android.os.Build.VERSION.SDK_INT;
            if (sdk < 11) {
                android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getActivity()
                        .getSystemService(Context.CLIPBOARD_SERVICE);
                response[0] = clipboard.getText().toString();
            } else {
                android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getActivity()
                        .getSystemService(Context.CLIPBOARD_SERVICE);
                ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0);
                response[0] = item.getText();
            }
        }
    });
    return response[0];
}