How Android Clipboard operations are used under different versions of the API

Source: Internet
Author: User

please use the Android.text.ClipboardManager before SDK11
Java code
  1. import Android.text.ClipboardManager;
  2. ......
  3. Clipboardmanager Clipboardmanager = (clipboardmanager) getsystemservice (Context.clipboard_service);
  4. Clipboardmanager.settext ("content");
  5. if (Clipboardmanager.hastext ()) {
  6. Clipboardmanager.gettext ();
  7. }


Android.text.ClipboardManager was discarded from SDK11, using its subclass android.content.ClipboardManager substitution, also discarded and settext/gettext/ HasText method, using Setprimaryclip/getprimaryclip/hasprimaryclip instead
Java code
  1. import Android.content.ClipboardManager;
  2. ......
  3. Clipboardmanager Clipboardmanager = (clipboardmanager) getsystemservice (Context.clipboard_service);
  4. Clipboardmanager.setprimaryclip (Clipdata.newplaintext (null, "content"));
  5. if (Clipboardmanager.hasprimaryclip ()) {
  6. Clipboardmanager.getprimaryclip (). Getitemat (0). GetText ();
  7. }
  8. public class Clipboardutils {


    @SuppressWarnings ("deprecation")
    public static void CopyToClipboard (context context, String text) {
    Android.text.ClipboardManager cbm = (Android.text.ClipboardManager) context.getsystemservice (context.clipboard_ SERVICE);
    Cbm.settext (text);

    }

    @SuppressWarnings ("deprecation")
    public static Charsequence Getclipboardtext (context context) {
    Android.text.ClipboardManager cbm = (Android.text.ClipboardManager) context.getsystemservice (context.clipboard_ SERVICE);
    return Cbm.gettext ();
    }
    }

How Android Clipboard operations are used under different versions of the API

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.