Chromium webview似乎不适用于Android applyOverrideConfiguration

时间:2015-08-17 12:45:05

标签: android webview chromium

根据我的更改在Force locale for Android flavor with resConfig中进行了描述我遇到了包含视频的网页视图的问题。问题仅出在API21 +上,并且在删除对applyOverrideConfiguration的调用时确实消失了。不太确定如何绕过它。

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)

从我在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

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;
 }

编辑:经过多次测试后,我能够在testApp中隔离崩溃。它可以在我在Chromium https://code.google.com/p/chromium/issues/detail?id=521753

上创建的bug报告中找到

有什么想法吗?任何人都遇到过这个问题吗?

2 个答案:

答案 0 :(得分:1)

与@Martin Edlman commented一样,它应该可以使用以下解决方法:

在科特林:

override fun getAssets(): AssetManager {
    return resources.assets
}

在Java中:

@Override
public AssetManager getAssets() {
    return getResources().getAssets();
} 

答案 1 :(得分:0)

为了未来;您可以尝试自己的实现。将以下代码添加到您的CustomChromeClient;

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