Class SharedContent

java.lang.Object
com.codename1.share.SharedContent

public final class SharedContent extends Object

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());
            }
        }
    }
}
  • Field Details

    • TYPE_TEXT

      public static final int TYPE_TEXT
      Item type: plain text.
      See Also:
    • TYPE_URL

      public static final int TYPE_URL
      Item type: a URL (delivered as text).
      See Also:
    • TYPE_FILE

      public static final int TYPE_FILE
      Item type: a file, exposed as a FileSystemStorage path.
      See Also:
    • TYPE_IMAGE

      public static final int TYPE_IMAGE
      Item type: an image, exposed as a FileSystemStorage path.
      See Also:
  • 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