Android text and input-copy and paste (1)

Source: Internet
Author: User

This article translated from: http://developer.android.com/guide/topics/text/copy-paste.html

Android provides a powerful clipboard-based framework for copying and pasting. It supports simple and complex data types, including text strings, complex data structures, text and binary stream data, and even application-to-program assets. Simple text data is stored in the clipboard, and complex data stores a reference. The pasted application uses the content provider to parse the reference. The copy and paste operations can be performed inside the application, or between two applications that implement the Framework.

Because this framework uses the content provider, this topic assumes that you are familiar with the android content provider API.
The providers topic is introduced.

Clipboard Frame

When using the clipboard framework, you put the data into a clip object, and then put the clip object to the system clipboard. Clip objects can be one of the following formats:

Text:A text string. You can directly put this string into the clip object and then put it on the system clipboard. Obtain the clip object from the clipboard and copy the string to your application memory.

Uri:Represents a URI object in the URI format. It is mainly used to copy complex data from the content provider. Put the URI object into a clip object, and then put the clip object to the system clipboard to copy the data. Obtain the clip object from the system clipboard, obtain the URI object, parse the data source (such as the content provider), and copy the data from the data source to the memory of your application.

Intent:It supports shortcuts for copying applications. To copy this data, you need to create an intent object, put it in a clip object, and put this clip object on the system clipboard. To paste data, you need to obtain the clip object from the clipboard and put the intent object in the memory of your application.

The system clipboard holds only one clip object each time. When an application puts a clip object on the clipboard, the previous clip object will be discarded.

If you want to allow users to paste data into your application, you do not have to process all data types. You can check the data on the clipboard before pasting. The clip object contains metadata that tells you the MIME type or available type. This metadata will help you determine whether your application can use the data on the clipboard. For example, if you want to process text, you can ignore clip objects that contain URI or intent objects.

You may also want users to paste text regardless of the data format on the clipboard. You can forcibly convert the Clipboard data to text format and then paste the text.

 

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.