Async pixel transfers not supported 和 Undefined

来源:互联网 发布:openstack 数据库服务 编辑:程序博客网 时间:2024/06/07 05:25


 

升级今年的客户端,发现在Android4.4以上的版本上出现webview界面无法显示,JavaScript无法交互。但是在4.4以下的版本中各个手机都运行正常

 

1、刚开始是第一次进去正常,在进去显示Undefined

2、然后是chromiuminitialize is not defined

3、最后是Async pixeltransfers not supported

 

这些问题是解决一个,紧接着出现另一个,搞的我头晕研发的

 

首先

Android 4.4以上,webview内核基于chromium

4.4以前基于webkit

 

下面是解释

Android 4.4 (API level 19) introduces a newversion of WebView that is based on Chromium. This change upgrades WebViewperformance and standards support for HTML5, CSS3, and JavaScript to match thelatest web browsers. Any apps using WebView will inherit these upgrades whenrunning on Android 4.4 and higher.

 

The current performance of Android webviewis so poor. ChromiumWebView gives your application early access to the newestfeatures in Chromium, and removes the variability due to different WebViewimplementations in different versions of Android.

 

The new (chromium based) WebView is faster– so far no surprise. But looking at the numbers, the performance has reallyincreased in several areas (like up to 354% for HTML5 Canvas or 358% for someJavascript test). So your WebView content should run way smoother and fasterthen before Old WebView vs. Chromium backed WebView

 

这是关于4.4谷歌给的两篇官方文档,里面详细说明的各种情况

https://developer.android.com/about/versions/android-4.4.html

https://developer.android.com/guide/webapps/migrating.html

 

第一个问题是因为在4.4js的交互变了,需要启动js和dom,并添加注解

 webSettings.setJavaScriptEnabled(true);

 webSettings.setDomStorageEnabled(true);

@JavascriptInterface  添加到每个交互的方法前面

 

 

第二个问题

  在新chromium内核下,webview更耗内存资源,必须在onPageFinished方法完成才可以和js进行交互

 

 

第三个问题

  不同的机器可能不同,具体看官方文档吧,这个chromium内核的

https://developer.chrome.com/multidevice/webview/pixelperfect

 

 

至此我的APP在各个版本都显示正常了,顺便怒草XXXX屏蔽谷歌

1 0