public class SystemPasteboard extends Object
This class facilitates short-term data exchange between user applications. For example, an application program uses this interface to paste copied data to the system pasteboard, and another program obtains the pasted data from the pasteboard.
In the distributed pasteboard scenario, the pasted data can be written across devices. For example, an application program on device A uses this interface to store data copied form device A to the system pasteboard of device B. An application program on device B can read and paste the copied data in the system pasteboard if the data is allowed to share between devices.
Note that the following conditions must be met for cross-device data writing:
SystemCapability.Miscservices#PASTEBOARD| 限定符和类型 | 方法 | 说明 |
|---|---|---|
void |
addPasteDataChangedListener(IPasteDataChangedListener listener) |
Listens for pasteboard content changes.
|
void |
clear() |
Clears the pasteboard.
|
PasteData |
getPasteData() |
Obtains data in a
PasteData object. |
static SystemPasteboard |
getSystemPasteboard(Context context) |
Obtains an object for system pasteboard operations.
|
boolean |
hasPasteData() |
Checks whether there is content in the pasteboard.
|
void |
removePasteDataChangedListener(IPasteDataChangedListener listener) |
Removes the listener for pasteboard content changes.
|
void |
setPasteData(PasteData data) |
Writes
PasteData to the pasteboard. |
public static SystemPasteboard getSystemPasteboard(Context context)
context - Indicates the application context. This parameter cannot be null.null if the input parameter is null,
or no object is obtained.public PasteData getPasteData()
PasteData object.
For purposes of user data security, non-foreground applications (excluding the default system input method
application) are not allowed to obtain pasteboard content. If an application does not have the focused window,
null will be returned.
In the distributed pasteboard scenario, the obtained data is the latest content written by the local or remote device into the local system pasteboard.
null if the operation is not allowed.PasteData,
setPasteData(PasteData),
hasPasteData()public void setPasteData(PasteData data)
PasteData to the pasteboard.
When cross-device data writing is allowed, calling this method will write the data into the system pasteboard of other devices in the network.
data - Indicates paste data to write.NullPointerException - Throws this exception if pasteData is null.PasteData,
getPasteData(),
hasPasteData()public boolean hasPasteData()
For the purposes of user data security, non-foreground applications are not allowed to check
pasteboard content. If an application does not have the focused window, false will be returned.
true if there is content;
returns false if there is no content, or the operation is not allowed.PasteData,
getPasteData(),
setPasteData(PasteData)public void clear()
public void addPasteDataChangedListener(IPasteDataChangedListener listener)
listener - Indicates the listener.IPasteDataChangedListenerpublic void removePasteDataChangedListener(IPasteDataChangedListener listener)
listener - Indicates the listener to remove.IPasteDataChangedListener