Dealing with deprecated android.text.ClipboardManager
I ended up just using the old way (android.text.ClipboardManager and the code from this answer), along with a couple @SuppressWarnings("deprecation") annotations.
Referring to this answer:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {final android.content.ClipboardManager clipboardManager = (android.content.ClipboardManager) context .getSystemService(Context.CLIPBOARD_SERVICE);final android.content.ClipData clipData = android.content.ClipData .newPlainText("text label", "text to clip");clipboardManager.setPrimaryClip(clipData);} else {final android.text.ClipboardManager clipboardManager = (android.text.ClipboardManager) context .getSystemService(Context.CLIPBOARD_SERVICE);clipboardManager.setText("text to clip");}
Explicitly:
@SuppressWarnings("deprecation") android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(CLIPBOARD_SERVICE); clipboard.setText(shareViaSMSBody);
Since this has to keep working on older devices, it is likely that the deprecated code will not be removed from Android.