简体   繁体   English

Chromium webview似乎不适用于Android applyOverrideConfiguration

[英]Chromium webview does not seems to work with Android applyOverrideConfiguration

Following my change describe in Force locale for Android flavor with resConfig I am facing a problem with webviews containing video. 在我的更改后使用resConfig描述Android风格的强制语言环境我面临包含视频的webview的问题。 The issue is only on API21+ and really disappear when removing the call to applyOverrideConfiguration. 问题仅出在API21 +上,并且在删除对applyOverrideConfiguration的调用时确实消失了。 Not so sure how to get around that. 不太确定如何解决这个问题。

java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
  at com.android.webview.chromium.WebViewContentsClientAdapter.getDefaultVideoPoster(WebViewContentsClientAdapter.java:1172)
  at org.chromium.android_webview.DefaultVideoPosterRequestHandler$1.run(DefaultVideoPosterRequestHandler.java:39)
  at android.os.Handler.handleCallback(Handler.java:739)
  at android.os.Handler.dispatchMessage(Handler.java:95)
  at android.os.Looper.loop(Looper.java:135)
  at android.app.ActivityThread.main(ActivityThread.java:5221)
  at java.lang.reflect.Method.invoke(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:372)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

From what I could find on grepcode it would be while getting the ic_media_video_poster image.. I validated that this image is really in the sdk. 从我在grepcode上可以找到的是获取ic_media_video_poster图像的时候..我验证了这个图像真的在sdk中。 http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/5.0.1_r1/com/android/webview/chromium/WebViewContentsClientAdapter.java#WebViewContentsClientAdapter.getDefaultVideoPoster%28%29 http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/5.0.1_r1/com/android/webview/chromium/WebViewContentsClientAdapter.java#WebViewContentsClientAdapter.getDefaultVideoPoster%28% 29

public Bitmap More ...getDefaultVideoPoster() {
     TraceEvent.begin();
     Bitmap result = null;
     if (mWebChromeClient != null) {
         if (TRACE) Log.d(TAG, "getDefaultVideoPoster");
         result = mWebChromeClient.getDefaultVideoPoster();
     }
     if (result == null) {
         // The ic_media_video_poster icon is transparent so we need to draw it on a gray
         // background.
         Bitmap poster = BitmapFactory.decodeResource(
                 mWebView.getContext().getResources(),
                 R.drawable.ic_media_video_poster);
         result = Bitmap.createBitmap(poster.getWidth(), poster.getHeight(), poster.getConfig());
         result.eraseColor(Color.GRAY);
         Canvas canvas = new Canvas(result);
         canvas.drawBitmap(poster, 0f, 0f, null);
     }
     TraceEvent.end();
     return result;
 }

EDIT : After a few more test, I was able to isolate the crash in a testApp. 编辑 :经过几次测试后,我能够在testApp中隔离崩溃。 It is available in the bugreport I created on Chromium https://code.google.com/p/chromium/issues/detail?id=521753 它可以在我在Chromium上创建的bug报告中找到https://code.google.com/p/chromium/issues/detail?id=521753

Any ideas? 有任何想法吗? As anyone faced this problem already? 任何人都遇到过这个问题?

For future; 为了未来; You can try my own implementation. 你可以尝试我自己的实现。 Add below code to your CustomChromeClient; 将以下代码添加到CustomChromeClient;

@Nullable
@Override
public Bitmap getDefaultVideoPoster() {
    if (super.getDefaultVideoPoster() == null) {
        return BitmapFactory.decodeResource(context.getResources(),
                R.drawable.ic_launcher);
    } else {
        return super.getDefaultVideoPoster();
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM