美文网首页
Android 含视频H5打开崩溃

Android 含视频H5打开崩溃

作者: 赵泓博 | 来源:发表于2020-04-08 14:21 被阅读0次

崩溃日志:
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$$Lambda0.run(Unknown Source:2) at android.os.Handler.handleCallback(Handler.java:873) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:6802) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInitMethodAndArgsCaller.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的配置图片,可能会出问题

相关文章

网友评论

      本文标题:Android 含视频H5打开崩溃

      本文链接:https://www.haomeiwen.com/subject/knrtmhtx.html