Class SharedContent
Content shared into the app from another application via the platform share sheet
(Android) or share extension / open-in flow (iOS). Delivered to the app through
com.codename1.system.Lifecycle#onReceivedSharedContent(SharedContent).
A shared payload may contain multiple items of mixed type (for example several images
shared at once). File and image items are exposed as paths in the Codename One
com.codename1.io.FileSystemStorage, having been copied out of the originating app's
sandbox by the platform port, so application code is fully platform neutral.
Usage
public class MyApp extends Lifecycle {
public void onReceivedSharedContent(SharedContent content) {
if (content.hasText()) {
handleText(content.getFirstItem().getText());
}
for (SharedContent.Item item : content.getItems()) {
if (item.getType() == SharedContent.TYPE_IMAGE) {
importImage(item.getFilePath());
}
}
}
}
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder forSharedContent.static final classA single item within a shared payload. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intItem type: a file, exposed as aFileSystemStoragepath.static final intItem type: an image, exposed as aFileSystemStoragepath.static final intItem type: plain text.static final intItem type: a URL (delivered as text). -
Method Summary
Modifier and TypeMethodDescriptionstatic SharedContent.Builderbuilder()Creates a new builder.Returns the first item, or null if the payload is empty.getItems()Returns the items contained in this shared payload.Returns the optional subject of the shared content (for example an email subject), or null if none was supplied.booleanhasFiles()Returns true if any item is a file or an image.booleanhasText()Returns true if any item is text or a URL.
-
Field Details
-
TYPE_TEXT
public static final int TYPE_TEXTItem type: plain text.- See Also:
-
TYPE_URL
public static final int TYPE_URLItem type: a URL (delivered as text).- See Also:
-
TYPE_FILE
public static final int TYPE_FILEItem type: a file, exposed as aFileSystemStoragepath.- See Also:
-
TYPE_IMAGE
public static final int TYPE_IMAGEItem type: an image, exposed as aFileSystemStoragepath.- See Also:
-
-
Method Details
-
getSubject
Returns the optional subject of the shared content (for example an email subject), or null if none was supplied.
Returns
the subject, or null
-
getItems
Returns the items contained in this shared payload.
Returns
the items, never null
-
getFirstItem
Returns the first item, or null if the payload is empty.
Returns
the first item, or null
-
hasText
public boolean hasText()Returns true if any item is text or a URL.
Returns
true if textual content is present
-
hasFiles
public boolean hasFiles()Returns true if any item is a file or an image.
Returns
true if file content is present
-
builder
Creates a new builder. Intended for use by the platform ports that construct the shared content before delivering it to the app.
Returns
a new builder
-