Get WebView version number for lollipop?

后端 未结 3 1939
傲寒
傲寒 2020-12-24 02:15

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?

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-24 03:14

    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.

提交回复
热议问题