Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get WebView version number for lollipop?

Tags:

android

I have Lollipop, and see that we have a separate app for "android system webview". Is there any way to get its version number from my own app that uses a WebView instance?

I'd like to report some stats on which version my users are using.

Thanks

like image 744
user3203425 Avatar asked Mar 19 '15 13:03

user3203425


People also ask

How do I find my WebView version?

Scroll down the App Info screen. At the bottom, the Android System Webview version number will be listed. For example, Version 83.0. 4103.106.

What version of Chrome WebView do I have Android?

To see what version of Chrome is currently used on a Lollipop device, simply go to Settings < Apps < Android System WebView and look at the version.

How do I find Android System WebView?

You can find the app at the following location: Settings → Application Manager → System Apps. Here, you will be able to see the Android System WebView app and check whether it is active or disabled. You might even be prompted to update it by visiting the Google Play Store.


Video Answer


2 Answers

How about checking the user-agent string?

Log.i("WebViewActivity", "UA: " + mWebView.getSettings().getUserAgentString()); 

For me, this outputs:

User-agent string: Mozilla/5.0 (Linux; Android 5.0; Nexus 4 Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/37.0.0.0 Mobile Safari/537.36

More info: WebView on Android

In case you override UA string with your own:

String getWebviewVersionInfo() {     // Overridden UA string     String alreadySetUA = mWebView.getSettings().getUserAgentString();      // Next call to getUserAgentString() will get us the default     mWebView.getSettings().setUserAgentString(null);      // Devise a method for parsing the UA string     String webViewVersion =             parseUAForVersion(mWebView.getSettings().getUserAgentString());      // Revert to overriden UA string     mWebView.getSettings().setUserAgentString(alreadySetUA);      return webViewVersion; } 
like image 118
Vikram Avatar answered Nov 01 '22 21:11

Vikram


UPDATE: Apparently this will not always accurately give the actual WebView client being used on the target device. As of Android 7.0 users can select preferred client (h/t @Greg Dan).


First, we get the package name from Google Play Store:

https://play.google.com/store/apps/details?id=com.google.android.webview

Then this

PackageManager pm = getPackageManager(); try {     PackageInfo pi = pm.getPackageInfo("com.google.android.webview", 0);     Log.d(TAG, "version name: " + pi.versionName);     Log.d(TAG, "version code: " + pi.versionCode); } catch (PackageManager.NameNotFoundException e) {     Log.e(TAG, "Android System WebView is not found"); } 

gives

D/WebViewDetails﹕ version name: 39 (1743759-arm) D/WebViewDetails﹕ version code: 320201 

Hope this helps.

like image 34
ozbek Avatar answered Nov 01 '22 21:11

ozbek