Code example for ClipboardManager

Methods: setPrimaryClip

0
    if (currentapiVersion >= android.os.Build.VERSION_CODES.HONEYCOMB) {
 
      android.content.ClipboardManager clipboard =
          (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
      ClipData clip = ClipData.newPlainText("Coinbase", text);
      clipboard.setPrimaryClip(clip);
    } else { 
 
      android.text.ClipboardManager clipboard =
          (android.text.ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
      clipboard.setText(text);
    } 
  } 
 
  @Override 
  protected void onListItemClick(ListView l, View v, int position, long id) {
 
    String address = (String)((Map<?, ?>) l.getItemAtPosition(position)).get("address");
    setClipboard(address);
    Toast.makeText(ReceiveAddressesActivity.this, getString(R.string.addresses_copied), Toast.LENGTH_SHORT).show();
  }