Through broker.share.* services, we can have access to functions that enable the user to share texts, images, videos, texts and images, invoking the share action of each platform. Moreover, users can share texts with other users by email simultaneously.

PUBLIC METHODS

void broker.share.shareText(String text)

It shares texts using the native controls of each platform.

Arguments  
text String: Text to be shared.
Exceptions
InvalidUIAction – Error when trying to execute shareText action outside application navigation stack.

void broker.share.shareMediaFile(MediaFile mediaFile)

It shares a photo or video through a MediaFile using the native controls of each platform.

Arguments  
mediaFile MediaFile: Photo or video to be shared.
Exceptions
InvalidUIAction – Error when trying to execute shareMediaFile action outside application navigation stack.

void broker.share.shareTextAndMediaFile(String text, MediaFile mediaFile)

It shares a text or photo through a MediaFile using the native controls of each platform.

Arguments  
text String: Text to be shared .
mediaFile MediaFile: Photo or video to be shared.
Exceptions
InvalidUIAction – Error when trying to execute shareTextAndMediaFile action outside application navigation stack.

Bool broker.share.canShareByEmail()

It returns true if the device has a configured email account.

Return  
Bool It returns true if the device has a configured email account.

void broker.share.shareByEmail(Array recipients, String subject, String emailBody)

It opens an email application configured with the fields of the arguments: recipient list, subject and body of the email.

Arguments  
destinatario Array: Recipients email addresses.
subject String: Subject of the email.
emailBody String: Body of the email.
Exceptions
ShareByMailConfigError – User has not set up the device for sending email.
InvalidUIAction – Error when trying to execute shareByEmail action outside application navigation stack.

Example:

Experience Main {
    Decision rule1 action("MainContext.shareText")         label("Share text")
    Decision rule2 action("MainContext.shareMediaFile")    label("Share image")
    Decision rule3 action("MainContext.shareTextAndMedia") label("Share text and image")
    Decision rule4 action("MainContext.shareEmail")        label("Share by email")
}

RuleContext MainContext {

    Rule shareText {
        broker.share.shareText("Hi, I am sharing a text!")
    }

    Rule shareMediaFile {
        MediaGalleryConfigure mgc = MediaGalleryConfigure()
        MediaFile mf = broker.media.open(mgc)
        broker.share.shareMediaFile(mf)
    }

    Rule shareTextAndMedia {
        String text = "This is the image subtitle"
        MediaGalleryConfigure mgc = MediaGalleryConfigure()
        MediaFile mf = broker.media.open(mgc)
        broker.share.shareTextAndMediaFile(text, mf)
    }

    Rule shareEmail {
        if (broker.share.canShareByEmail()) {
            Array<String> recipients = []
            recipients.add("john@gmail.com")
            broker.share.shareByEmail(recipients, "Subject", "Hey, check this out this new platform, it's called Mat|r")
        }
    }
}