# Class SharedContent

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

public final class SharedContent extends java.lang.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());
                }
            }
        }
    }

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static final class`
  `SharedContent.Builder`
  Builder for `SharedContent`.
  `static final class`
  `SharedContent.Item`
  A single item within a shared payload.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final int`
  `TYPE_FILE`
  Item type: a file, exposed as a `FileSystemStorage` path.
  `static final int`
  `TYPE_IMAGE`
  Item type: an image, exposed as a `FileSystemStorage` path.
  `static final int`
  `TYPE_TEXT`
  Item type: plain text.
  `static final int`
  `TYPE_URL`
  Item type: a URL (delivered as text).

- ## Method Summary

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

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### TYPE_TEXT

    public static final int TYPE_TEXT
    Item type: plain text.
    See Also:
      - Constant Field Values

  - ### TYPE_URL

    public static final int TYPE_URL
    Item type: a URL (delivered as text).
    See Also:
      - Constant Field Values

  - ### TYPE_FILE

    public static final int TYPE_FILE
    Item type: a file, exposed as a `FileSystemStorage` path.
    See Also:
      - Constant Field Values

  - ### TYPE_IMAGE

    public static final int TYPE_IMAGE
    Item type: an image, exposed as a `FileSystemStorage` path.
    See Also:
      - Constant Field Values

- ## 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