JonaNorman пре 1 година
родитељ
комит
bb5f22ce47

+ 50 - 0
README-ZH.md

@@ -0,0 +1,50 @@
+# WebViewUpgrade
+简体中文 | [English](./README.md)
+这个库实现了Android免安装升级WebView内核的功能。
+Android5.0以后WebView升级需要去安装APK才行,国内没有Google Play的情况都无法找到升级包,就算找到了像华为、Amazon等特殊机型WebView的Chromium版本一般比较低,只能用它自己的WebView无法用Google的WebView。
+我就遇到了在华为机上用WebView无法播放H265视频的情况,因为Chromium版本低于107就无法播放H265视频。 为了解决上述问题,一般常规做法是用JS实现H265播放,但是会比较卡,这个时候我就想能不能让WebView用应用内的APK作为内核,下图是升级WebView内核的前后效果对比
+![preview](preview/preview.gif)
+明显发现在华为机上系统的WebView内核包名是com.huawei.webview版本是14.0.0.331,UserAgent中的Chromium实际版本是99.0.4844.88,如下图所示小于107不支持H265播放
+![webview_can_not_play_h265](preview/webview_can_not_play_h265.jpg)
+把WebView内核的包名、版本、包地址传到以下代码升级内核成功后就可以播放H265视频了
+![upgrade_code.png](preview/upgrade_code.png)
+WebView内核选择页面如下图所示
+![choose_webview.jpg](preview/choose_webview.jpg)
+升级成功的WebView内涵的包名变成了com.google.android.webview,UserAgent中的Chromium实际版本也变成了122.0.6261.64
+![webview_can_play_h265.png](preview/webview_can_play_h265.png)
+
+# 兼容性
+
+Android的设备五花八门,已测试以下功能和机型,欢迎大家提issue和Merge Request加入到这个项目中来
+## 功能特性
+| WebView包名    | 系统版本 |
+|:-------------| ----- |
+|com.google.android.webview     | 122.0.6261.64  |
+| com.android.webview       | 113.0.5672.136      |
+| com.huawei.webview   | 14.0.0.331     |
+| com.android.chrome | 122.0.6261.43     |
+| com.amazon.webview.chromium | 118-5993-tv.5993.155.51   |
+
+## 机型
+| 厂商         | 系统版本 |
+| :----------- | -------- |
+| 华为Mate30   | 12       |
+| 小米10       | 11       |
+| VIVO NEX A   | 10       |
+| OPPO FIND X5 | 14       |
+
+**待开发功能**
+
+- [ ] 多进程
+- [ ] 动态切换
+
+
+# ⭐ star历史
+
+![Star History Chart](https://api.star-history.com/svg?repos=JonaNorman/WebViewUpgrade&type=Date)
+
+
+# 特别感谢
+| Stargazers                                                                                                 | Forkers                                                                                                                 |
+|---------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------|
+| [![Stargazers repo roster for @JonaNorman/HDRSample](https://reporoster.com/stars/JonaNorman/WebViewUpgrade)](https://github.com/JonaNorman/WebViewUpgrade/stargazers)                                          | [![Forkers repo roster for @JonaNorman/HDRSample](https://reporoster.com/forks/JonaNorman/WebViewUpgrade)](https://github.com/JonaNorman/WebViewUpgrade/network/members)                            |

+ 65 - 1
README.md

@@ -1 +1,65 @@
-todo
+# WebViewUpgrade
+
+English | [简体中文](./README-ZH.md)
+
+This library implements the functionality of upgrading the WebView kernel on Android without installation.
+
+After Android 5.0, upgrading WebView requires installing an APK. In situations where Google Play is not available, it's impossible to find the update package. Even if found, special device models like Huawei and Amazon typically have lower versions of WebView's Chromium, which cannot be replaced with Google's WebView.
+
+I encountered a situation where WebView couldn't play H265 videos on a Huawei device due to the Chromium version being lower than 107. To resolve this issue, the conventional approach is usually to implement H265 playback using JavaScript, but this can be sluggish. At this point, I wondered if WebView could use the APK within the application as its kernel. The image below shows the before and after effects of upgrading the WebView kernel:
+
+![preview](preview/preview.gif)
+
+It's apparent that on Huawei devices, the WebView kernel package name is `com.huawei.webview` with a version of 14.0.0.331. The Chromium version in the UserAgent is actually 99.0.4844.88, as shown in the image below. It does not support H265 playback as it is less than 107:
+
+![webview_can_not_play_h265](preview/webview_can_not_play_h265.jpg)
+
+After successfully upgrading the kernel using the code provided below, WebView can play H265 videos:
+
+![upgrade_code.png](preview/upgrade_code.png)
+
+The WebView kernel selection page looks like the image below:
+
+![choose_webview.jpg](preview/choose_webview.jpg)
+
+After successful upgrade, the WebView package name changes to `com.google.android.webview`, and the Chromium version in the UserAgent becomes 122.0.6261.64:
+
+![webview_can_play_h265.png](preview/webview_can_play_h265.png)
+
+## Compatibility
+
+Android devices vary greatly. The following features and device models have been tested. Contributions through issue submission and Merge Requests to this project are welcomed.
+
+### Feature Characteristics
+
+| WebView Package Name         | System Version      |
+|:-----------------------------| ------------------- |
+| com.google.android.webview  | 122.0.6261.64       |
+| com.android.webview         | 113.0.5672.136      |
+| com.huawei.webview          | 14.0.0.331          |
+| com.android.chrome          | 122.0.6261.43       |
+| com.amazon.webview.chromium | 118-5993-tv.5993.155.51 |
+
+### Device Models
+
+| Manufacturer  | System Version |
+| :------------ | -------------- |
+| Huawei Mate30 | 12             |
+| Xiaomi 10     | 11             |
+| VIVO NEX A    | 10             |
+| OPPO FIND X5  | 14             |
+
+**Upcoming Features**
+
+- [ ] Multi-process
+- [ ] Dynamic Switch
+
+# ⭐ Star History
+
+![Star History Chart](https://api.star-history.com/svg?repos=JonaNorman/WebViewUpgrade&type=Date)
+
+# Special Thanks
+
+| Stargazers                                                                                                 | Forkers                                                                                                                 |
+|---------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------|
+| [![Stargazers repo roster for @JonaNorman/HDRSample](https://reporoster.com/stars/JonaNorman/WebViewUpgrade)](https://github.com/JonaNorman/WebViewUpgrade/stargazers)                                          | [![Forkers repo roster for @JonaNorman/HDRSample](https://reporoster.com/forks/JonaNorman/WebViewUpgrade)](https://github.com/JonaNorman/WebViewUpgrade/network/members)                            |

+ 19 - 19
app/src/main/java/com/norman/webviewup/demo/MainActivity.java

@@ -80,13 +80,7 @@ public class MainActivity extends Activity implements UpgradeCallback {
         findViewById(R.id.upgradeButton).setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
-                if (WebViewUpgrade.isProcessing()) {
-                    Toast.makeText(getApplicationContext(), "webView is being upgraded, please wait", Toast.LENGTH_LONG).show();
-                } else if (WebViewUpgrade.isCompleted()) {
-                    Toast.makeText(getApplicationContext(), "webView is already upgrade success,not support dynamic switch", Toast.LENGTH_LONG).show();
-                } else {
-                    showChooseWebViewDialog();
-                }
+                showChooseWebViewDialog();
             }
         });
 
@@ -136,18 +130,24 @@ public class MainActivity extends Activity implements UpgradeCallback {
         builder.setItems(items, new DialogInterface.OnClickListener() {
             @Override
             public void onClick(DialogInterface dialog, int which) {
-                UpgradeInfo upgradeInfo = UPGRADE_PACKAGE_LIST.get(which);
-                selectUpgradeInfo = upgradeInfo;
-                UpgradeOptions upgradeOptions = new UpgradeOptions
-                        .Builder(getApplicationContext(),
-                        upgradeInfo.packageName,
-                        upgradeInfo.url,
-                        upgradeInfo.versionName,
-                        new DownloadSinkImpl())
-                        .build();
-                WebViewUpgrade.upgrade(upgradeOptions);
-                updateUpgradeWebViewPackageInfo();
-                updateUpgradeWebViewStatus();
+                if (WebViewUpgrade.isProcessing()) {
+                    Toast.makeText(getApplicationContext(), "webView is being upgraded, please wait", Toast.LENGTH_LONG).show();
+                } else if (WebViewUpgrade.isCompleted()) {
+                    Toast.makeText(getApplicationContext(), "webView is already upgrade success,not support dynamic switch", Toast.LENGTH_LONG).show();
+                } else {
+                    UpgradeInfo upgradeInfo = UPGRADE_PACKAGE_LIST.get(which);
+                    selectUpgradeInfo = upgradeInfo;
+                    UpgradeOptions upgradeOptions = new UpgradeOptions
+                            .Builder(getApplicationContext(),
+                            upgradeInfo.packageName,
+                            upgradeInfo.url,
+                            upgradeInfo.versionName,
+                            new DownloadSinkImpl())
+                            .build();
+                    WebViewUpgrade.upgrade(upgradeOptions);
+                    updateUpgradeWebViewPackageInfo();
+                    updateUpgradeWebViewStatus();
+                }
             }
         });
         AlertDialog dialog = builder.create();

BIN
preview/choose_webview.jpg


BIN
preview/preview.gif


BIN
preview/upgrade_code.png


BIN
preview/webview_can_not_play_h265.jpg


BIN
preview/webview_can_play_h265.png