Copy text to Android

Source: Internet
Author: User

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 ;}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.