Determine WebView Implementation (System WebView or Chrome)

DataDino picture DataDino · Dec 20, 2016 · Viewed 12.2k times · Source

Android 7.0 allows users (via developer options) to choose the implementation of their WebView. The user can choose the standalone WebView or use the Chrome APK to render WebViews. Reference

Since this potentially means those who use WebViews now have two different code bases to worry about, it would be useful to know which implementation is currently selected.

Is there a way to determine what WebView implementation is selected in Android 7?

Answer

DataDino picture DataDino · Mar 21, 2017

Looks like this now available in Android O Preview:

Link: https://developer.android.com/preview/features/managing-webview.html

Starting in Android 7.0 (API level 24), users can choose among several different packages for displaying web content in a WebView object. Android O includes an API for fetching information related to the package that is displaying web content in your app. This API is especially useful when analyzing errors that occur only when your app tries to display web content using a particular package's implementation of WebView.

To use this API, add the logic shown in the following code snippet:

PackageInfo webViewPackageInfo = WebView.getCurrentWebViewPackage();
Log.d(TAG, "WebView version: " + webViewPackageInfo.versionName);

WebView.getCurrentWebViewPackage Documentation: https://developer.android.com/reference/android/webkit/WebView.html#getCurrentWebViewPackage()