Functions
Javascript Interface functions
We've developed a set of all purpose functions that you can use from your webapp to interact with your native application. We have documented them below.
Use our demo app to try out the interface functions: Example
Vibrate
Vibrate the device. Takes vibration duration (in milliseconds) as a function parameter.
Note: Requires `android.permission.VIBRATE` to be declared in the manifest file.
// vibrate the device for 1 second
.vibrate(1000);
Toast
Show native toast. Takes text to be shown in the toast and duration (0 for short and 1 for long duration).
.toast("Hello World", 0)
Copy To Clipboard
Copy text to the clipboard. It needs only one function parameter, the text to be copied.
.copyToClipboard("Sample Text")
Get installed apps list
It returns the list of package name of installed apps.
.getInstalledAppList()
Start an app activity
Start an activity within the application. It takes 2 parameters, activity name(class name of the activity to navigate to) and intent parameters(json of parameters to be passed to activity in string format).
.startActivity("in.workindia.rapidwebviewandroidsample.MainActivity", "{"key1": 1, "key2": "value2"}")
Open Browser
Open external browser as a new window. It takes two paramters, url(complete url to visit) and package name(name of browser package to open eg: "com.android.chrome").
.openBrowserActivity("https://www.google.com/", "com.android.chrome")
Open Chrome Custom Tab
To open a chrome custom tab. It takes two parameters, url(complete url to visit) and color(Chrome custom tab color). Color in the form of string eg.) "#483D8B", "#80FFFFFF" and "red".
.openCustomBrowserTab("https://www.google.com/", "#483D8B")
Place a call / Open dialer
Open a dialer (and call a number if permission is granted). It only requires one paramter the mobile number in the form of string.
Note: Requires permission `android.permission.CALL_PHONE` to place a call.
.openDialer("1234567890")
Open an external intent (eg, google maps)
To open a new application. It requires two parameters, package name(name of package to open), and intent uri.
.openExternalIntent("com.google.android.gms.maps", "geo:37.7749,-122.4194")
Open native share dialog
To open android's native share dailog. It requires only one paramter, the text to be shared.
.openShareIntent("Try RapidWebView SDK: https://github.com/workindia/RapidWebView")
Share to an application (eg, slack)
Share text with a specific app. It requires two parameters, the package name of the app with which text is need to be shared, and second paramter the text to be shared.
.shareToApp("com.Slack", "Checkout this SDK: https://github.com/workindia/RapidWebView")
Check if permissions granted (eg, android.permission.CALL_PHONE)
Check if permission is granted by user. It requires only one paramter, the array of permissions to check.
.checkForPermission([ "android.permission.CALL_PHONE"])
Request permission
To ask for android permission. It requires 2 parameters, an array containing all the permissions needed, rationale Text(text to show on permission dialog), and a callback.
Events: Callbacks from native can be used by using javascript event listener with the event "rapid-web-view-permission-listener" which will return object { detail: { "status" : "success","uploadUrl" : "$uploadUrl","uploadFileName" : "$fileName"} }
.requestPermissions(["android.permission.CALL_PHONE"], "Permission required")
Show notification
To show notification to user. It requires 6 parameters, title for the notification, context text, summary text, notification icon, notification image, destination activity(activity to open when notification is clicked).
Note: Starting from Android 13 (SDK 33/TIRAMISU), it requires the `android.permission.POST_NOTIFICATIONS` permission.
.showNotification("Test Notification","Test Content","Test Summary","","","in.workindia.rapidwebviewandroidsample.MainActivity"
Close current activity
Close the activity that holds the web view.
.closeActivity()
Open native file upload interface
To upload a file using native file upload interface. It accepts 3 parameters, the file type, upload Url(where the file will be uploaded), and third a method to either "PUT" or "POST".
Events: Callbacks from native can be used by using javascript event listener with the event "rapid-web-view-upload-listener" which will return object { detail: { "status" : "success","uploadUrl" : "$uploadUrl","uploadFileName" : "$fileName"} }
Note: As the method uses foreground service for uploading files, on Devices running Android 9 (SDK 29/Q) or above, it requires `android.permission.FOREGROUND_SERVICE` and `android.permission.FOREGROUND_SERVICE_DATA_SYNC` permissions.
.uploadFile("doc", "www.example.com/uploadfile", "PUT|POST")
Download a File Locally
Downloads a file using the native DownloadManager. This function accepts three parameters: `url` (String), the mandatory URL of the file to download; `fileName` (String), an optional parameter that specifies the name of the saved file, defaulting to the last segment of the URL if not provided; and `downloadLocation` (String), which specifies the save location. `downloadLocation` can be 'EXTERNAL_FILES' (app-specific storage) or 'PUBLIC_DOWNLOADS' (default).
Events: Callbacks from native can be used by using javascript event listener with the event `rapid-web-view-download-listener` which will return object `{ detail: { eventKey: "downloadCompleted", status: "success|failure", downloadId: "downloadId" } }`.
Note: On devices running Android 9 (API level 28) or lower, ensure the WRITE_EXTERNAL_STORAGE permission is granted.
.downLoadFileLocally("https://example_files/example.pdf","example.pdf","PUBLIC_DOWNLOADS")
Download and Open a File
Downloads a file and opens it using the native DownloadManager. This function accepts three parameters: `url` (String), the mandatory URL of the file to download; `fileName` (String), an optional parameter that specifies the name of the saved file, defaulting to the last segment of the URL if not provided; and `downloadLocation` (String), which specifies the save location. `downloadLocation` can be 'EXTERNAL_FILES' (app-specific storage) or 'PUBLIC_DOWNLOADS' (default).
Events: Callbacks from native can be used by using javascript event listener with the event `rapid-web-view-download-listener` which will return object `{ detail: { eventKey: "downloadCompleted|downloadUnsuccessful|packageNotFound", status: "success|failure", downloadId: "downloadId" } }`.
Note: For devices running Android 9 (API level 28) or lower, ensure both WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE permissions are granted.
.downloadFileLocallyAndOpenIntent("https://picsum.photos/200/300","example.png","EXTERNAL_FILES")