Android clipboard.getText() is deprecated; how then to get the text item that's in it?

Please understand that the clipboard is not purely for text. Complex constructs can be placed on the clipboard, in the form of 1 to N ClipData.Item objects inside the ClipData object that you are getting from getPrimaryClip().

Given your ClipData, call getItemCount() to determine the number of items. For whichever item(s) you wish to attempt to use, call getItemAt() on the ClipData to get the corresponding ClipData.Item. On that item, you can call getText() or coerceToText() to try to get a text representation of that item.


Use below code

String copyString = clipboard.getPrimaryClip().getItemAt(0).getText()