If you work with data in Microsoft Excel, you may find yourself needing to frequently copy and paste links to data between cells. Rather than take the time to copy and paste each link individually, you can use the Excel paste link shortcut to quickly copy and paste all links at once. Show
To use the Excel paste link shortcut, first select the cell or range of cells that you want to copy. Then, press Ctrl+C to copy the cells. Next, select the cell or range of cells where you want to paste the links. Finally, press Ctrl+Alt+V to paste the links. The Excel paste link shortcut is a quick and easy way to copy and paste links between cells. By using this shortcut, you can save yourself time and effort when working with data in Excel. Android provides a powerful clipboard-based framework for copying and pasting. It supports both simple and complex data types, including text strings, complex data structures, text and binary stream data, and even application assets. Simple text data is stored directly in the clipboard, while complex data is stored as a reference that the pasting application resolves with a content provider. Copying and pasting works both within an application and between applications that implement the framework. Since a part of the framework uses content providers, this topic assumes some familiarity with the Android Content Provider API, which is described in the topic Content Providers. Users expect feedback when copying content to the clipboard, so in addition to the framework that powers copy and paste, Android shows a default UI to users when copying in Android 13 (API level 33) and higher. You should continue to manually provide feedback to users when copying in Android 12L (API level 32) and lower. See our recommendations for how to do that later in this guide. The Clipboard FrameworkWhen you use the clipboard framework, you put data into a clip object, and then put the clip object on the system-wide clipboard. The clip object can take one of three forms: Text A text string. You put the string directly into the clip object, which you then put onto the clipboard. To paste the string, you get the clip object from the clipboard and copy the string to into your application's storage. URI AUri object representing any form of URI. This is primarily for copying complex data from a content provider. To copy data, you put a
Uri object into a clip object and put the clip object onto the clipboard. To paste the data, you get the clip object, get the Uri object, resolve it to a data source such as a content provider, and copy the data from the source into your application's storage. Intent An Intent . This supports copying application shortcuts. To copy data, you create an
Intent, put it into a clip object, and put the clip object onto the clipboard. To paste the data, you get the clip object and then copy the Intent object into your application's memory area. The clipboard holds only one clip object at a time. When an application puts a clip object on the clipboard, the previous clip object disappears. If you want to allow users to paste data into your application, you don't have to handle all types of data. You can examine the data on the clipboard before you give users the option to paste it. Besides having a certain data form, the clip object also contains metadata that tells you what MIME type or types are available. This metadata helps you decide if your application can do something useful with the clipboard data. For example, if you have an application that primarily handles text, you may want to ignore clip objects that contain a URI or Intent. You may also want to allow users to paste text regardless of the form of data on the clipboard. To do this, you can force the clipboard data into a text representation, and then paste this text. This is described in the section Coercing the clipboard to text. Clipboard ClassesThis section describes the classes used by the clipboard framework. ClipboardManager In the Android system, the system clipboard is represented by the global ClipData, ClipData.Item, and ClipDescription To add data to the clipboard, you create a A A CharSequence . URI A
Uri . This usually contains a content provider URI, although any URI is allowed. The application that provides the data puts the URI on the clipboard. Applications that want to paste the data get the URI from the clipboard and use it to access the content provider (or other data source) and retrieve the data. Intent An Intent . This data type allows you to
copy an application shortcut to the clipboard. Users can then paste the shortcut into their applications for later use. You can add more than one ClipData convenience methods The newPlainText(label, text) Returns a ClipData object whose
single ClipData.Item object contains a text string. The ClipDescription object's label is set to label . The single MIME type in ClipDescription is MIMETYPE_TEXT_PLAIN . Use newUri(resolver, label, URI) Returns a ClipData object whose single ClipData.Item object contains a URI. The ClipDescription object's label is set to label . If the URI is a content URI (Uri.getScheme() returns content: ), the method uses the ContentResolver object provided in resolver to retrieve the available MIME types
from the content provider and store them in ClipDescription . For a URI that is not a content: URI, the method sets the MIME type to MIMETYPE_TEXT_URILIST . Use newIntent(label, intent) Returns a ClipData object whose single ClipData.Item object contains an Intent . The ClipDescription object's label is set to label . The MIME type is set to MIMETYPE_TEXT_INTENT . Use Coercing the clipboard data to text Even if your application only handles text, you can copy non-text data from the clipboard by converting it with the method This method converts the data in ClipData.Item is text (getText() is not null), coerceToText() returns the text. URI
If ClipData.Item is a URI (getUri() is not null), coerceToText() tries to use it as a content URI:
ClipData.Item is an Intent (getIntent() is not null), coerceToText() converts it to an Intent URI and returns it. The representation is the same as that returned by Intent.toUri(URI_INTENT_SCHEME) . The clipboard framework is summarized in Figure 1. To copy data, an application puts a
Figure 1. The Android clipboard framework Copying to the Clipboard As described previously, to copy data to the clipboard you get a handle to the global
Provide feedback when copying to the clipboardUsers expect visual feedback when an app copies content to the clipboard. This is done automatically for users in Android 13 and higher but must be manually implemented in prior versions. Starting in Android 13, the system displays a standard visual confirmation when content is added to the clipboard. The new confirmation does the following:
In Android 12L (API level 32) and lower, users are often unsure when they have successfully copied content or what they have copied. This feature standardizes the various notifications shown by apps after copying and offers users more control over their clipboard. UI shown when content enters the clipboard in Android 13 and up.Avoid duplicate notificationsIn Android 12L (API level 32) and lower, we suggest alerting users that they’ve successfully copied by issuing a visual pop-up in-app widget (like Toasts or Snackbars) after copying. To avoid duplicate displays of information, we strongly recommend removing any pop-up widget shown after an in-app copy for Android 13 and higher. If you show a copy confirmation snackbar in Android 13, the user sees duplicate messages. If you show a copy confirmation toast in Android 13, the user sees duplicate messages.Here's an example of how to implement this: fun textCopyThenPost(textCopied:String) { val clipboardManager = getSystemService(CLIPBOARD_SERVICE) as ClipboardManager // When setting the clip board text. clipboardManager.setPrimaryClip(ClipData.newPlainText("", textCopied)) // Only show a toast for Android 12 and lower. if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.S_V2) Toast.makeText(context, “Copied”, Toast.LENGTH_SHORT).show() } Add sensitive content to the clipboard If your app allows users to copy sensitive content, such as passwords or credit card information, to the clipboard, you must add a flag to ClipData’s To flag sensitive content, add a boolean extra to the // When your app targets API level 33 or higher clipData.apply { description.extras = PersistableBundle().apply { putBoolean(ClipDescription.EXTRA_IS_SENSITIVE, true) } } // If your app targets a lower API level clipData.apply { description.extras = PersistableBundle().apply { putBoolean("android.content.extra.IS_SENSITIVE", true) } } Pasting from the ClipboardAs described previously, you paste data from the clipboard by getting the global clipboard object, getting the clip object, looking at its data, and if possible copying the data from the clip object to your own storage. This section explains in detail how to paste the three forms of clipboard data. Pasting plain text To paste plain text, first get the global clipboard and verify that it can return plain text. Then get the clip object and copy its text to your own storage using
Pasting data from a content URI If the The following procedure describes how to get data from a content provider based on a content URI on the clipboard. It checks that a MIME type that the application can use is available from the provider:
Pasting an Intent To paste an Intent, first get
the global clipboard. Examine the
System notification shown when your app accesses clipboard dataOn Android 12 (API level 31) and higher, the system usually shows a toast message when your app calls APP pasted from your clipboard The system doesn't show a toast message when your app does one of the following:
Using Content Providers to Copy Complex DataContent providers support copying complex data such as database records or file streams. To copy the data, you put a content URI on the clipboard. Pasting applications then get this URI from the clipboard and use it to retrieve database data or file stream descriptors. Since the pasting application only has the content URI for your data, it needs to know which piece of data to retrieve. You can provide this information by encoding an identifier for the data on the URI itself, or you can provide a unique URI that will return the data you want to copy. Which technique you choose depends on the organization of your data. The following sections describe how to set up URIs, how to provide complex data, and how to provide file streams. The descriptions assume that you are familiar with the general principles of content provider design. Encoding an identifier on the URIA useful technique for copying data to the clipboard with a URI is to encode an identifier for the data on the URI itself. Your content provider can then get the identifier from the URI and use it to retrieve the data. The pasting application doesn't have to know that the identifier exists; all it has to do is get your "reference" (the URI plus the identifier) from the clipboard, give it your content provider, and get back the data. You usually encode an identifier onto a content URI by concatenating it to the end of the URI. For example, suppose you define your provider URI as the following string: "content://com.example.contacts" If you want to encode a name onto this URI, you would use the following snippet:
If you are already using a content provider, you may want to add a new URI path that indicates the URI is for copying. For example, suppose you already have the following URI paths: "content://com.example.contacts"/people "content://com.example.contacts"/people/detail "content://com.example.contacts"/people/images You could add another path that is specific to copy URIs: "content://com.example.contacts/copying" You could then detect a "copy" URI by pattern-matching and handle it with code that is specific for copying and pasting. You normally use the encoding technique if you're already using a content provider, internal database, or internal table to organize your data. In these cases, you have multiple pieces of data you want to copy, and presumably a unique identifier for each piece. In response to a query from the pasting application, you can look up the data by its identifier and return it. If you don't have multiple pieces of data, then you probably don't need to encode an identifier. You can simply use a URI that is unique to your provider. In response to a query, your provider would return the data it currently contains. Getting a single record by ID is used in the Note Pad sample application to open a note from the notes list. The sample uses the Copying data structures You set up a content provider for copying and pasting complex data as a subclass of the
In the content provider, you will want to override at least the following methods: query() Pasting applications will assume that they can get your data by using this method with the URI you put on the clipboard. To support copying, you should have this method detect URIs that contain a special "copy" path. Your application can then create a "copy" URI to put on the clipboard, containing the copy path and a pointer to the exact record you want to copy. getType() This
method should return the MIME type or types for the data you intend to copy. The method newUri() calls getType() in order to put the MIME types into the new ClipData object. MIME types for complex data are described in the topic Content Providers. Notice that you don't have to have any of the other content provider methods such as The following snippets demonsrate how to set up your application to copy complex data:
The section Pasting data from a content URI describes how to get a content URI from the clipboard and use it to get and paste data. Copying data streamsYou can copy and paste large amounts of text and binary data as streams. The data can have forms such as the following:
A content provider for data
streams provides access to its data with a file descriptor object such as To set up your application to copy a data stream with a provider, follow these steps:
To paste a data stream, an application gets the clip from the clipboard, gets the URI, and uses it in a call to a The following list shows
the most important file descriptor methods for a content provider. Each of these has a corresponding openTypedAssetFile() This method should return an asset file descriptor, but only if the provided MIME type is supported by the provider. The caller (the application doing the pasting) provides a MIME type pattern. The content provider (of the application
that has copied a URI to the clipboard) returns an AssetFileDescriptor file handle if it can provide that MIME type, or throws an exception if it can not. This method handles subsections of files. You can use it to read assets that the content provider has copied to the clipboard. openAssetFile() This method is a more general form of openTypedAssetFile() . It does not filter for allowed MIME types, but it can read subsections of files. openFile() This is a more general form of
openAssetFile() . It can't read subsections of files. You can optionally use the Designing Effective Copy/Paste FunctionalityTo design effective copy and paste functionality for your application, remember these points:
What is the advantage to embedding an object rather than copying and pasting it?What is the advantage to embedding an object rather than copying and pasting it? The object can be edited in the destination program using the tools of the source program.
When you edit the source file of a linked object on a slide What happens to the linked object?When an object is linked, information can be updated if the source file is modified. Linked data is stored in the source file. The Word file, or destination file, stores only the location of the source file, and it displays a representation of the linked data.
What is embedded data in Excel?Embedding generally refers to inserting an object created in an alternative software (Word or PDF, etc. ) in Excel. Embedding is the process of incorporating an object from another software into an Excel worksheet.
When you paste formula cells using the Paste button in the Clipboard group Which of the following is true?When you paste formula cells using the paste button in the clipboard group, which of the following is true? The paste options button then lets you paste specific elements of the copied cells.
|