Android Webview Integration

When developing an app in Android that includes a WebView component, a few
additional steps are needed to ensure that Viafoura's social login capabilities function properly.

The Android WebView component provides a subset of the functionality of the
Android Webkit browser. The WebView's behavior deviates from regular browsers
in the way that it manages popup windows. When a popup window is opened from a link in a page within a WebView, it is opened separately in the Android browser,
and not within the same WebView. This breaks the continuity of the web page, and
makes it impossible to return control to the page hosted with a WebView in the
app.

Viafoura's social login process requires a popup window to manage the
authentication process with the appropriate social network. Once the social
network has authorized a user's credentials, the popup window is closed, and the
originating site will now be logged into Viafoura.

Implementation

This document and supporting repository will provide you with clear steps on implementation.

Host an HTTPS Page that Serves the Widget
Please review MainActivity.kt for a sample implementation of Viafoura's social login.

The WebView's controller must:

  1. In the main WebView's settings
    i. Set: javaScriptCanOpenWindowsAutomatically = true
    ii. Set: domStorageEnabled = true
    iii. Set: javaScriptEnabled = true
    iv. Set: loadsImagesAutomatically = true
    v. Set: blockNetworkImage = false
    vi. Set: setSupportMultipleWindows(true)
    vii. To enable social login with Google, set:
    userAgentString = "Mozilla/5.0 (Linux; Android 7.0; SM-G930V Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.125 Mobile Safari/537 .36"

  2. A custom WebViewWebChromeClient for the WebView displaying the page
    i. Implement the onCreateWindow handler for that WebViewWebChromeClient
    which opens a dialog (or similar subview structure) and child WebView
    ii. Implement onCloseWindow to allow the WebView to close

  3. In the child WebView
    i. Implement onCheckIsTextEditor to enable the soft keyboard
    ii. Implement an onPageFinished handler in its WebViewClient

📘

Note

The implementation of Viafoura's tools in a WebView can be difficult.

Contact our support team for more information and assistance.


Did this page help you?