Enabling WebView for tunneling

Ensure that you add this method call right before calling webview.loadUrl(url).

The MicroVPNSDK.enableWebViewObjectForNetworkTunnel(…) method is used to update a WebView object before loading the WebView. After the network tunnel is established successfully, the MicroVPNSDK.enableWebViewObjectForNetworkTunnel(…) method needs to be called before calling webView.loadUrl(url). This method returns the modified WebView object that is enabled for tunneling. Since #startTunnel(…) is an asynchronous call, the tunnel needs to be started before calling this API. Otherwise it throws a NetworkTunnelNotStartedException exception.

Note:

Do not update the WebView or WebViewClient object after the #enabledWebViewObjectForNetworkTunnel(…) call. So, calling MicroVPNSDK.enableWebViewObjectForNetworkTunnel(…) right before webview.loadUrl(url) is the recommended approach.

    WebView webView = findViewById(R.id.webview);
    try {
        WebViewClient webviewClient = new WebViewClient();
        webView.setWebViewClient(webviewClient);
        webView = MicroVPNSDK.enableWebViewObjectForNetworkTunnel(this, webView, webviewClient);
        webView.loadUrl(url);
    } catch(NetworkTunnelNotStartedException nse) {
        Log.e(LOG_TAG, nse.getMessage());
    } catch(MvpnException e) {
        Log.e(LOG_TAG, e.getMessage());
    }
 <!--NeedCopy-->
Enabling WebView for tunneling

In this article