/ Android is cut board operation

Use clipboard in Android

You can access the clipboard ClipboardManager service

**Main code is as follows: **

import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.text.ClipboardManager; import android.text.TextUtils; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class ClipboardTestActivity extends Activity implements OnClickListener { private EditText editText; private Button copyButton; private Button pasteButton; private Button clearButton; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); editText = (EditText) findViewById(R.id.editText1); copyButton = (Button) findViewById(R.id.button1); pasteButton = (Button) findViewById(R.id.button2); clearButton = (Button) findViewById(R.id.button3); copyButton.setOnClickListener(this); pasteButton.setOnClickListener(this); clearButton.setOnClickListener(this); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.button1: copy("Number:" + Math.random() * 100); break; case R.id.button2: paste(editText); break; case R.id.button3: clear(); break; default: break; } } private void clear() { ClipboardManager clipboardManager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); clipboardManager.setText(null); } private void paste(EditText editText) { ClipboardManager clipboardManager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); CharSequence text = clipboardManager.getText(); if (TextUtils.isEmpty(text)) { Toast.makeText(this, "The clipboard is empty!", Toast.LENGTH_SHORT).show(); return; } editText.setText(text); } private void copy(String text) { ClipboardManager clipboardManager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); clipboardManager.setText(text); } }


  1. Copy: Produce a number randomly, install clipboard next;
  2. Paste: Obtain data from clipboard,  installing EditText;
  3. Clear: Clear empty clipboard—-Stopped with Copy principle actually;

** PS:** Detailed content asks referenced developer documentation! : )