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:
-
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"
-
A custom
WebViewWebChromeClient
for theWebView
displaying the page
i. Implement theonCreateWindow
handler for thatWebViewWebChromeClient
which opens adialog
(or similar subview structure) and childWebView
ii. ImplementonCloseWindow
to allow theWebView
to close -
In the child
WebView
i. ImplementonCheckIsTextEditor
to enable the soft keyboard
ii. Implement anonPageFinished
handler in itsWebViewClient
Note
The implementation of Viafoura's tools in a
WebView
can be difficult.
Contact our support team for more information and assistance.
Updated 29 days ago