Hello. It is necessary to somehow take the copied text from the buffer (I copied the text, through toast what I copied was output). How to do it?
2 answers
Try this
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); String pasteData = ""; // If it does contain data, decide if you can handle the data. if (!(clipboard.hasPrimaryClip())) { } else if (!(clipboard.getPrimaryClipDescription().hasMimeType(MIMETYPE_TEXT_PLAIN))) { // since the clipboard has data but it is not plain text } else { //since the clipboard contains plain text. ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0); // Gets the clipboard as text. pasteData = item.getText().toString(); } } - Thank you so much :) - CrazyProgrammist
|
If you just need to show a toast confirming that the data has been copied, it is not necessary to read the data from the buffer. Just show the toast with what was copied.
Here we copied the text getYourText() .
ClipboardManager mClipboardManager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); ClipData clipData = ClipData.newPlainText("mText", getYourText()); mClipboardManager.setPrimaryClip(clipData ); And here we immediately showed it.
Toast.makeText(this, getYourText(), Toast.LENGTH_SHORT).show(); |