Android SDK Installation
Android SDK Installation
This guide explains how you can integrate RapidWebView SDK in to your Android Application.
Dependency
Begin by adding Jitpack to your root build.gradle
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Add sdk to your app's build.gradle
dependencies {
...
implementation 'com.github.workindia:RapidWebView:[latest-version]'
}
Initialising RapidClient
Initialise RapidClient in StartApplication
of your applicationimport in.workindia.rapidwebview.assetcache.RapidAssetCacheDownloader;
...
RapidClient.createInstance(this);
Initialising RapidAssetCacheDownloader
Initialise the asset cache downloader by passing it url to asset-manifest.json (Read more about the manifest here). The downloader also accepts retry-count as second parameter which will be used to determine how many times the downloader will retry in case of an error. Asset cache initialisation needs to be done soon after the application opens, before the webview is loaded. The operation does not run on UI thread and will not impact the users experience.import in.workindia.rapidwebview.assetcache.RapidAssetCacheDownloader;
...
RapidAssetCacheDownloader.initialise(
"https://rapid-web-view.netlify.app/_next/static/assets-manifest.json",
5
);
Setting up a webview with RapidWebViewClient
Add RapidWebViewClient to a webview in your app. This client intercepts requests made by the webview and responds with a local asset copy if it's available.import in.workindia.rapidwebview.RapidWebViewClient;
...
private WebView mWebView;
...
// Initialise mWebView and add WebSettings of your choice
mWebView.setWebViewClient(new RapidWebViewClient());
mWebView.loadUrl("https://rapid-web-view.netlify.app/");
Adding the RapidWebViewJSInterface
(optional)
We have included a Javascript interface with a few generic use-cases which interacts with native android functionality.import in.workindia.rapidwebview.RapidWebViewJSInterface;
...
mWebView.addJavascriptInterface(
new RapidWebViewJSInterface(this, this, mWebView), "app"
);
You can read more about the Js Interface functions here
Permissions
(optional)
In order to support certain functionalities within JavascriptInterface, you may add following permissions to your AndroidManifest.xml. <uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
Next: Setup a web app which uses WebPack. Webapp Setup