Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
496 views
in Technique[技术] by (71.8m points)

android - Get WebView version number for lollipop?

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...