android.text.ClipboardManager
was deprecated since API level 11, and replaced with android.content.ClipboardManager
(source).
How do I write code that supports both cases? Importing android.content.ClipboardManager
and using that works in 11+ but force closes in 10. Changing the import to android.text.ClipboardManager
throws a bunch of deprecation warnings in 11+.
How can I handle both cases smoothly? What do I need to import?
I ended up just using the old way (android.text.ClipboardManager and the code from this answer), along with a couple @SuppressWarnings("deprecation") annotations.
If you are still supporting < SDK 11 you are doing too much work. Set min to 15 and use this code:
Explicitly:
Since this has to keep working on older devices, it is likely that the deprecated code will not be removed from Android.
Referring to this answer: