public final class SharedContent

  1. Object
  2. 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 types

class SharedContent.ItemA single item within a shared payload.
class SharedContent.BuilderBuilder for SharedContent.

Fields

public static final int TYPE_TEXT = 1Item type: plain text.
public static final int TYPE_URL = 2Item type: a URL (delivered as text).
public static final int TYPE_FILE = 3Item type: a file, exposed as a FileSystemStorage path.
public static final int TYPE_IMAGE = 4Item type: an image, exposed as a FileSystemStorage path.

Methods

public String getSubject()Returns the optional subject of the shared content (for example an email subject), or null if none was supplied.
public SharedContent.Item[] getItems()Returns the items contained in this shared payload.
public SharedContent.Item getFirstItem()Returns the first item, or null if the payload is empty.
public boolean hasText()Returns true if any item is text or a URL.
public boolean hasFiles()Returns true if any item is a file or an image.
public static SharedContent.Builder builder()Creates a new builder.

Inherited methods

Field details

TYPE_TEXT

public static final int TYPE_TEXT = 1
Item type: plain text.

TYPE_URL

public static final int TYPE_URL = 2
Item type: a URL (delivered as text).

TYPE_FILE

public static final int TYPE_FILE = 3
Item type: a file, exposed as a FileSystemStorage path.

TYPE_IMAGE

public static final int TYPE_IMAGE = 4
Item type: an image, exposed as a FileSystemStorage path.

Method details

getSubject

public String 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

public SharedContent.Item[] getItems()
Returns the items contained in this shared payload.

Returns

the items, never null

getFirstItem

public SharedContent.Item 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

public static SharedContent.Builder 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