Android, the ability to directly copy related content in the client, is already a more useful function, and also provides the relevant API.
It should be noted that the compatibility of low-version mobile phone when using, pay attention to determine the API version, the code is as follows:
New View. Onclicklistener() {@SuppressLint ("Newapi") @Override public void OnClick (View v) {if (Getsdkversionnumber () >= One) {Android. Text. ClipboardmanagerClipboardmanager = (Android. Text. Clipboardmanager) context. Getsystemservice(Context. CLIPBOARD_service); Clipboardmanager. SetText(Linkurl); }else{//Get Clipboard manager Android. Content. ClipboardmanagerClipboardmanager = (Android. Content. Clipboardmanager) context. Getsystemservice(Context. CLIPBOARD_service); Clipboardmanager. Setprimaryclip(Clipdata. Newplaintext(null, Linkurl));} toastutil. Show(Context,"copied to Pasteboard");} }
How to get the phone OS version:
/** * 获取手机操作系统版本 * @return * @author SHANHY * @date 2015年12月4日 */ publicstaticintgetSDKVersionNumber() { int sdkVersion; try { sdkVersion = Integer.valueOf(android.os.Build.VERSION.SDK); catch (NumberFormatException e) { 0; } return sdkVersion; }
Android Copy Text