崩溃日志:
2018-10-18 14:52:36.782 29843-29843/com.hugboga.custom E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.hugboga.custom, PID: 29843
java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
at com.android.webview.chromium.Ap.getDefaultVideoPoster(WebViewContentsClientAdapter.java:585)
at org.chromium.android_webview.DefaultVideoPosterRequestHandler$$LambdaMethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:868)
2018-10-18 14:52:36.806 29843-30223/com.hugboga.custom W/.hugboga.custo: Accessing hidden method Landroid/telephony/TelephonyManager;->getSimCount()I (light greylist, reflection)
2018-10-18 14:52:36.806 29843-30223/com.hugboga.custom W/.hugboga.custo: Accessing hidden method Landroid/telephony/TelephonyManager;->getSimSerialNumber(I)Ljava/lang/String; (light greylist, reflection)
2018-10-18 14:52:36.807 29843-30223/com.hugboga.custom W/.hugboga.custo: Accessing hidden method Landroid/telephony/TelephonyManager;->getSubscriberId(I)Ljava/lang/String; (light greylist, reflection)
2018-10-18 14:52:36.807 29843-30223/com.hugboga.custom W/.hugboga.custo: Accessing hidden method Landroid/telephony/SubscriptionManager;->getSubId(I)[I (light greylist, reflection)
在Android9.0中,含视频的H5需要增加默认播放之前的图片展示,如果没有就会出现该错误
解决办法如下:
public class PieChromeClient extends WebChromeClient {
@Override
public Bitmap getDefaultVideoPoster() {
try {
return BitmapFactory.decodeResource(MyApplication.getAppContext().getResources(),
R.drawable.home_guide_dafault);
} catch (Exception e) {
return super.getDefaultVideoPoster();
}
}
}
在WebView设置中,设置
webView.setWebChromeClient(new PieChromeClient(){...})
注意:
保证drawable是图片,如果是xml的配置图片,可能会出问题
网友评论