Copy text to Android
In Android, the client provides the function of directly copying related content, which is a relatively practical function. Android also provides related APIs.
It should be noted that when using a mobile phone compatible with a lower version, pay attention to the API version. The method code is as follows:
New View. onClickListener () {@ SuppressLint ("NewApi") @ Override public void onClick (View v) {if (getSDKVersionNumber ()> = 11) {android. text. clipboardManager clipboardManager = (android. text. clipboardManager) context. getSystemService (Context. CLIPBOARD_SERVICE); clipboardManager. setText (linkUrl);} else {// obtain the clipboard manager android. content. clipboardManager clipboardManager = (android. content. clipboardManager) context. getSystemService (Context. CLIPBOARD_SERVICE); clipboardManager. setPrimaryClip (ClipData. newPlainText (null, linkUrl);} ToastUtil. show (context, "copied to clipboard ");}}
How to get the mobile OS version:
/*** Get the mobile OS version ** @ return * @ author SHANHY * @ date July 15, December 4, 2015 */public static int getSDKVersionNumber () {int sdkVersion; try {sdkVersion = Integer. valueOf (android. OS. build. VERSION. SDK);} catch (NumberFormatException e) {sdkVersion = 0;} return sdkVersion ;}