这是今天一个朋友问我的问题(解决方案在最后一段)。因为没有遇到过,第一反应就是借助搜索引擎。也确实搜到一些解决方案,但是源码不在我这里没办法尝试。其实这个问题的原因很容易就能想到,WebView在不同的系统版本有不同的实现,而这个问题出现在7.0以上(8.0也会出现,9.0没有实测就不清楚了),说明这是系统的bug。解决系统的bug思路也很简单:无非两种方案,1、另起炉灶;2、弥补系统的bug。
对于第一种解决方案,就是弃用WebView,通常我们会使用X5WebView。这个方案我没有实测,不过理论上应该行得通的。
而第二种方案,我们要分析出现问题的原因:Resources$NotFoundException,资源找不到,极有可能是加载资源时就出现问题了。要解决这个问题要对不同版本的WebView的源码比较熟悉,网上也有对此进行分析的文章(Android7.0中的ResourceNotFoundException),读者们可以自行去研究一下。
最后我贴出一个解决方案:github.com/Qihoo360/Re… 、 github.com/Qihoo360/Re… ,可以看出360团队的对WebView的源码是非常熟悉的,点个赞!
W/ResourceType: No known package when getting value for resource number 0x02080005
W/System.err: android.content.res.Resources$NotFoundException: Resource ID #0x2080005
W/System.err: at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:216)
at android.content.res.Resources.getInteger(Resources.java:1097)
at org.chromium.ui.base.DeviceFormFactor.a(PG:4)
at IT.onCreateActionMode(PG:5)
at com.android.internal.policy.DecorView$ActionModeCallback2Wrapper.onCreateActionMode(DecorView.java:3040)
at com.android.internal.policy.DecorView.startActionMode(DecorView.java:1160)
at com.android.internal.policy.DecorView.startActionModeForChild(DecorView.java:1116)
at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:916)
I/chatty: uid=10489(u0_a489) com.hwsdk.sdk identical 1 line
W/System.err: at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:916)
at android.view.View.startActionMode(View.java:7101)
at IS.a(PG:15)
at org.chromium.content.browser.selection.SelectionPopupControllerImpl.s(PG:148)
at org.chromium.content.browser.selection.SelectionPopupControllerImpl.showSelectionMenu(PG:125)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:325)
at android.os.Looper.loop(Looper.java:142)
at android.app.ActivityThread.main(ActivityThread.java:6938)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
复制代码