Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

public class ClipboardContent

  1. Object
  2. ClipboardContent

Known subtypesRichTextClipboardData

A set of alternative clipboard representations keyed by MIME type. A clipboard write should normally include text/plain plus any richer formats it can provide. Clipboard readers negotiate by inspecting #getMimeTypes() and requesting the representation they understand best.

Values are usually String or byte[]. Ports may support additional native value types, but must retain the plain-text representation when one is supplied.

Fields

public static final String MIME_TEXT = "text/plain"
public static final String MIME_HTML = "text/html"
public static final String MIME_RTF = "text/rtf"
public static final String MIME_MARKDOWN = "text/markdown"
public static final String MIME_ASCIIDOC = "text/asciidoc"
public static final String MIME_PNG = "image/png"PNG image bytes (byte[]).
public static final String MIME_JPEG = "image/jpeg"JPEG image bytes (byte[]).
public static final String MIME_GIF = "image/gif"GIF image bytes (byte[]).
public static final String MIME_FILE = "application/x-file-list"A local file reference (a file path / URI String, or a String[] for several files).
public static final String MIME_URI_LIST = "text/uri-list"A newline separated list of URIs, the format desktop browsers and file managers use when a link or a file is dragged out of them.

Constructors

public ClipboardContent()

Methods

public ClipboardContent setSensitive(boolean sensitive)Marks this content as sensitive: a password, a one-time code, a recovery key, an account number.
public boolean isSensitive()Whether #setSensitive(boolean) marked this content sensitive.
public ClipboardContent setClearAfter(int millis)Takes the content off the clipboard again after the given time.
public int getClearAfter()The time #setClearAfter(int) set, in milliseconds, or 0.
public ClipboardContent setData(String mimeType, Object value)Adds or replaces a representation.
public ClipboardContent setDataProvider(String mimeType, ClipboardDataProvider provider)Declares a representation that is only built if something reads it, which is how a drag offers a file it has not written yet or an image it has not encoded yet.
public Object getData(String mimeType)Returns the representation for a MIME type, or null when it isn’t available.
public byte[] getBytes(String mimeType)Returns the binary (byte[]) representation for a MIME type – e.g. the raw bytes of an image or file – or null when it isn’t available or isn’t binary.
public String getText(String mimeType)Returns a string representation, or null when the value isn’t a string.
public boolean hasMimeType(String mimeType)Returns true when this content includes the requested MIME type.
public String[] getMimeTypes()Returns the available MIME types in preference order.
public ClipboardContent setFiles(String[] paths)Sets the #MIME_FILE representation from a list of file paths or file: URIs.
public String[] getFiles()Returns the #MIME_FILE representation as a path array regardless of whether the producer stored one String or a String[], or null when no files are available.
public String findPreferredMimeType(String[] preferredMimeTypes)Returns the first available MIME type from the caller’s preference list, or null.

Inherited methods

Field details

MIME_TEXT

public static final String MIME_TEXT = "text/plain"

MIME_HTML

public static final String MIME_HTML = "text/html"

MIME_RTF

public static final String MIME_RTF = "text/rtf"

MIME_MARKDOWN

public static final String MIME_MARKDOWN = "text/markdown"

MIME_ASCIIDOC

public static final String MIME_ASCIIDOC = "text/asciidoc"

MIME_PNG

public static final String MIME_PNG = "image/png"
PNG image bytes (byte[]).

MIME_JPEG

public static final String MIME_JPEG = "image/jpeg"
JPEG image bytes (byte[]).

MIME_GIF

public static final String MIME_GIF = "image/gif"
GIF image bytes (byte[]).

MIME_FILE

public static final String MIME_FILE = "application/x-file-list"
A local file reference (a file path / URI String, or a String[] for several files).

MIME_URI_LIST

public static final String MIME_URI_LIST = "text/uri-list"
A newline separated list of URIs, the format desktop browsers and file managers use when a link or a file is dragged out of them.

Constructor details

ClipboardContent

public ClipboardContent()

Method details

setSensitive

public ClipboardContent setSensitive(boolean sensitive)

Marks this content as sensitive: a password, a one-time code, a recovery key, an account number. Each port hides or confines it as far as its platform allows:

  • Android (API 33 and newer) tags the clip with ClipDescription.EXTRA_IS_SENSITIVE, so the system’s copy preview and keyboard suggestions do not show its text.
  • iOS publishes it local only (UIPasteboardOptionLocalOnly), so Universal Clipboard never sends it to the user’s other devices.
  • The simulator and the browser have no such marker; there the flag only matters together with #setClearAfter(int).

Parameters

sensitive boolean
true to mark the content sensitive

Returns

this instance, for chaining

isSensitive

public boolean isSensitive()
Whether #setSensitive(boolean) marked this content sensitive.

setClearAfter

public ClipboardContent setClearAfter(int millis)
Takes the content off the clipboard again after the given time. iOS lets the pasteboard expire it (UIPasteboardOptionExpirationDate), which works even if the application is suspended or killed meanwhile. Elsewhere the application clears the clipboard when the time is up, provided it has copied nothing else since and the clipboard still holds this content – a copy another application made meanwhile is left alone. That needs the application to be running, so it is a best effort rather than a guarantee. On Android 10 and later a background application cannot read the clipboard, so it cannot tell whether the clip is still this content; the clear then waits until the application returns to the foreground and runs only if the clipboard still holds this content. Until then the content can outlive the time given here. Outside iOS the pending clear lives only in the running process: if the application is killed before it runs, nothing clears the content. An application that must not leave it behind records a digest of what it copied (never the text) and, at its next start, clears the clipboard if it still holds content with that digest.

Parameters

millis int
the time the content stays on the clipboard, 0 (the default) to keep it

Returns

this instance, for chaining

getClearAfter

public int getClearAfter()
The time #setClearAfter(int) set, in milliseconds, or 0.

setData

public ClipboardContent setData(String mimeType, Object value)
Adds or replaces a representation. Passing null removes the MIME type.

setDataProvider

public ClipboardContent setDataProvider(String mimeType, ClipboardDataProvider provider)

Declares a representation that is only built if something reads it, which is how a drag offers a file it has not written yet or an image it has not encoded yet.

The provider is asked at most once and its answer is then cached, so #getData(java.lang.String) behaves exactly as it would for a value passed to #setData(java.lang.String, java.lang.Object). It may run on a native clipboard or drag thread; see ClipboardDataProvider. Passing a null provider removes the MIME type.

Parameters

mimeType String
the MIME type this provider can produce
provider ClipboardDataProvider
the provider, or null to remove the representation

Returns

this instance, for chaining

getData

public Object getData(String mimeType)

Returns the representation for a MIME type, or null when it isn’t available.

A representation registered through #setDataProvider(java.lang.String, com.codename1.ui.ClipboardDataProvider) is produced here, on the first call for that MIME type.

getBytes

public byte[] getBytes(String mimeType)
Returns the binary (byte[]) representation for a MIME type – e.g. the raw bytes of an image or file – or null when it isn’t available or isn’t binary.

getText

public String getText(String mimeType)
Returns a string representation, or null when the value isn’t a string.

hasMimeType

public boolean hasMimeType(String mimeType)
Returns true when this content includes the requested MIME type.

getMimeTypes

public String[] getMimeTypes()
Returns the available MIME types in preference order.

setFiles

public ClipboardContent setFiles(String[] paths)

Sets the #MIME_FILE representation from a list of file paths or file: URIs.

Ports differ on whether a single file is carried as a String or a one element String[]; this writes the form the rest of the framework expects, and #getFiles() reads either.

Parameters

paths String[]
the file paths, or null to remove the representation

Returns

this instance, for chaining

getFiles

public String[] getFiles()
Returns the #MIME_FILE representation as a path array regardless of whether the producer stored one String or a String[], or null when no files are available.

findPreferredMimeType

public String findPreferredMimeType(String[] preferredMimeTypes)
Returns the first available MIME type from the caller’s preference list, or null.