title: How to get the text from a ClipData object?
body: <p>In Android, the way to get the clipboard text <a href="https://stackoverflow.com/questions/6651184/set-text-and-get-text-from-clipboard">used to be simple</a>:</p>
  
  <pre><code>ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); 
  String text = clipboard.getText();
  </code></pre>
  
  <p>The <code>getText()</code> method has now been deprecated, and the <a href="https://developer.android.com/reference/android/content/ClipboardManager.html#getText()" rel="nofollow noreferrer">documentation</a> says to use <code>getPrimaryClip()</code> instead:</p>
  
  <blockquote>
    <p>getText()</p>
    
    <p>This method was deprecated in API level 11. Use getPrimaryClip() instead. This retrieves the primary clip and tries to coerce it to a string.</p>
  </blockquote>
  
  <p>However, <code>getPrimaryClip()</code> returns a <code>ClipData</code> object, and it is not clear how to get the text content in this object. How can that be achieved?</p>