Synapse: Android SDK
This webview SDK is made to work in conjunction with its web counterpart npm module - https://www.npmjs.com/package/@tata1mg/synapse
Table of Contents
Overview
1mg WebView SDK helps android app to easily communicate with frontend through java script bridge and vice-versa. There are set of callback functions defined which helps to communicate and pass data between two platforms.
Integration
- Add the SDK dependency to your build.grade file.
- Create one activity and implement OneMgWebViewActivity and override the abstract functions.
Steps to load web page
To load webpage call the makeRequest function with two parameters - url and HeaderMap (HeaderMap is optional here).
makeRequest function params:-
url – the URL of the resource to load.
HeaderMap – map with additional headers
Functions for communication
Navigator - This function is used to open, close, reload and back webpage.
- Opens the route defined.
- Closes the current WebView.
- Navigates back to the previous web page.
- Reloads the current WebView page.
Permission - This function required to request camera and location permission.
Logger - Logs any console-level errors or info.
Toolbar - Pass type as set and data from webpage to set the native toolbar title and icon. User can override toolbar function to define the implementation.
Interaction - Used to display a Native Toast message. Call interaction function with type “showToastMessage” and data to display toast.
Format of data to pass from webpage to display toast:-
{
type: "showToastMessage",
data: {
message: ""
}
}
- Analytics - Sends analytics events data to native.
Web can call this function to fire analytics events by passing data in json format. App needs to override analytics function and define its functionality.
- PostMessage - This method can we used to handle your app specific use cases.