In Android, the way to get the clipboard text used to be simple:
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
String text = clipboard.getText();
The getText()
method has now been deprecated, and the documentation says to use getPrimaryClip()
instead:
getText()
This method was deprecated in API level 11. Use getPrimaryClip() instead. This retrieves the primary clip and tries to coerce it to a string.
However, getPrimaryClip()
returns a ClipData
object, and it is not clear how to get the text content in this object. How can that be achieved?