SharinPix WebView on a Native Android Mobile Application

A WebView is a component inside a Java Android application which allows the display of a web app inside a mobile application. By running the SharinPix web app inside a WebView, your native Java Android application will contain the SharinPix experience usually available on Salesforce and the web. It can be seen as the equivalent of an iframe tag in HTML.

  • The folks at AppCoda have a simple tutorial on how to include a basic WebView in your application. You can follow it and try embedding SharinPix in your own app.

  • You have to use the link **https://app.sharinpix.com/?token=XXXXX **in your created WebView with a generated token.

Below is an example of a apex code:

    token = sharinpix.Client.getInstance().token(
        new Map<String, Object> {
            'Id' => wOrder.Id, //example of an albumId
            'exp' => 0,
            'path' => '/pagelayout/' + wOrder.Id,
            'abilities' => new Map<String, Object> {
                wOrder.Id => new Map<String, Object> {
                    'Access' => new Map<String, Boolean> {
                        'see' => true,
                        'image_list' => true,
                        'image_upload' => true,
                        'image_delete' => true
                    }
                },
                'Display' => new Map<String, Object> {
                    'tags'=> true
                }
            }
        }
    );

The code below demonstrates how to create a SharinPixWebView using the onCreate method in the activity.

It sets a listener setOnResultListener to check all the returning results from the SharinPixWebView controller. Based on this example when a result is returned, a popup/toast is shown.

In the onActivityResult method, it sends the activity results to the SharinPixWebView controller.

Steps for Installing SharinPixWebView Library

In settings.gradle include this line:

In build.gradle for your project module include this line:

Check for latest release on GitHub or Maven Central Repository Search: https://github.com/SharinPix/sharinpixwebview-android or https://search.maven.org/artifact/io.github.SharinPix/sharinpixwebview-android

Example for Overriding the onActivityFunction Function

Make sure to override the onActivityResult function in your activity and pass the parameters to the custom function on SharinPixWebView.

Example for Creating an Instance of SharinPixWebView

When creating a new instance of SharinPixWebView, you should pass the following parameter:

  • Activity: the main activity from which your WebView

  • WebView ID

  • URL

Example for Implementing the SharinPixWebView Listener

To be able to receive post messages from the SharinPix application, make sure to implement the custom listener.

The screenshot below shows images that are uploaded on the SharinPix application.

The screenshot shows a native toast being shown on the mobile application with the event that has been triggered when deleting an image on the SharinPix application.

Last updated