Official Content

It is increasingly common for users to share information from an application by using other applications installed on the device (e.g. Instagram, Facebook, Gmail, Hangouts, Dropbox). The Share external object lets you share content with any third-party application registered in the device to receive shared content.

Warning: Keep in mind that not all applications allow sharing any kind of content, it is necessary to consider each case independently depending on each platform. Check the Troubleshooting and Notes sections for details and differences between platforms.

Shareexternalobject-Location_png Share external object - Definition

Note: For specific social media sharing, Facebook and Twitter external objects are also available.

Properties

It does not have any

Methods

ShareText method

Shares a text. Optionally, an URL and a title can be added (otherwise, leave them empty). 

Return value  None
Parameters text:VarChar(200) [ , url:URL ] [ , title:VarChar(200) ]
 

ShareImage method

It allows sharing an Image. Optionally, a text, an URL and a title can be attached to it.

Return value  None
Parameters image:Image [ , text:VarChar(200) ] [ , url:URL ] [ , title:VarChar(200) ]
 

ShareFile method

It allows sharing a File (e.g. a PDF file generated by the application). Optionally, a text, and a title can be provided.

Return value  None
Parameters fileURI:VarChar [ , text:VarChar(200), title:VarChar(200) ]
 

Note: in iOS the text parameter is ignored.

This method is available as of GeneXus 17 upgrade 7.

Events

It does not have any

Examples

ShareText & ShareImage

In LightCRM, suppose we want users to share information about the meeting.

To do this, we add a “Share” button to the Application Bar of the Work with Meeting object.

SharingAPI - Layout

Next, we program the Event associated with this button.

Event 'Share'
    Composite
        If not CompanyLogo.IsEmpty()
            msg("Sharing meeting with image",status)
            Share.ShareImage(CompanyLogo, MeetingTitle,!"http://www.genexus.com",MeetingNote)
        Else
            msg("Sharing meeting",status)
            Share.ShareText(MeetingTitle,!"http://www.genexus.com",MeetingNote)
        EndIf
    EndComposite
EndEvent

The application will look as shown below. Clicking on the button displays a pop-up dialog that shows the applications installed on our device for sharing content. Lastly, you must to select one of these applications and share it!

SharingAPI - iOS button

ShareFile

Supsose that you have an offline application that generates a PDF file, and you want to give your users the possibility of exporting that file to save it to a cloud storage provider, like Dropbox, Google Drive, or iCloud.

You coud then have a GeneratePDF Procedure with the following rules

parm(in:&fileName, out:&fileUrl);
output_file(&fileName, "PDF");

and this code somewhere in the source part:

&filePath = Directory.TemporaryFilesPath + &file.Separator + &name + '.' + &extension
&fileUrl = !'file://' + &filePath

To share the generated PDF file from an action in your application, you could add a button with the following associated event:

Event 'ShareFile'
    composite
        &fileUrl = GeneratePDF('Sample')
        GeneXus.Social.Share.ShareFile(&fileUrl)
    endcomposite
EndEvent

Note:

  • All the variables in the previous code examples are defined as VarChar, except for the &file variable that is based on the File type.

Notes

  • Not all parameters specified in the methods will be shown in all applications when you share content, except for those that are required or accepted by the applications.
  • The URL parameter should be complete, following the format <scheme>://<domain>[<port>]/<path>. Otherwise, the URL is considered relative to the Service URL of the application. 

Troubleshooting

Not all third-party application accept any kind of content. 

For example,

  • Facebook always is exposed as a "share-with" application but does not allow to share plain text, it only allows you sharing images and URLsbut not both at the same time.
  • WhatsApp allows you to share images only if text, title, and URL are empty; otherwise, the image will not be sent.
  • Twitter ignores title parameters.
  • GMail takes the title as the subject of the email and text as its content.
  • WeChat on iOS: it is not allowed to share a text without an image/URL.

These limitations depend on the external application receiving the content.

Scope

Platforms  Smart Devices (iOS, Android), Angular

Availability

This external object is available as of GeneXus 15.

See also


Last update: April 2024 | © GeneXus. All rights reserved. GeneXus Powered by Globant