WebView无法正确加载html

时间:2017-08-17 15:12:07

标签: android webview httpurlconnection

我试图通过AsyncTask使用HttpUrlConnection将网页加载到WebView中更加聪明。 以前我使用过WebView' .loadurl()

我已经使用http://www.google.co.uk进行了测试,这似乎工作正常。 我从日志中得到了下面的输出,但是我无法确定加载这个特定页面的实际问题是什么。

我无法想象的是它为什么谈论支持或不支持的音频/视频编解码器。网页上没有这些内容。

将HTML加载到webview中时,我使用:

view.loadData(result, "text/html; charset=UTF-8", null);

抱歉这么直率的问题。

08-17 15:59:00.610 26720-26720/com.admin.phonedivert D/INFO: <html>.....
08-17 15:59:00.616 26720-26720/com.admin.phonedivert I/cr_Ime: ImeThread is enabled.
08-17 15:59:00.652 26720-26920/com.admin.phonedivert E/libEGL: validate_display:255 error 3008 (EGL_BAD_DISPLAY)
08-17 15:59:00.664 26720-26920/com.admin.phonedivert W/AudioCapabilities: Unsupported mime audio/evrc
08-17 15:59:00.665 26720-26920/com.admin.phonedivert W/AudioCapabilities: Unsupported mime audio/qcelp
08-17 15:59:00.668 26720-26920/com.admin.phonedivert W/VideoCapabilities: Unrecognized profile 2130706433 for video/avc
08-17 15:59:00.674 26720-26920/com.admin.phonedivert W/Utils: could not parse long range '175-174'
08-17 15:59:00.675 26720-26920/com.admin.phonedivert W/AudioCapabilities: Unsupported mime audio/dsd
08-17 15:59:00.675 26720-26920/com.admin.phonedivert W/AudioCapabilities: Unsupported mime audio/alac
08-17 15:59:00.676 26720-26920/com.admin.phonedivert W/AudioCapabilities: Unsupported mime audio/qcelp
08-17 15:59:00.676 26720-26920/com.admin.phonedivert W/AudioCapabilities: Unsupported mime audio/evrc
08-17 15:59:00.686 26720-26920/com.admin.phonedivert W/VideoCapabilities: Unsupported mime video/divx
08-17 15:59:00.688 26720-26920/com.admin.phonedivert W/VideoCapabilities: Unsupported mime video/divx311
08-17 15:59:00.690 26720-26920/com.admin.phonedivert W/VideoCapabilities: Unsupported mime video/divx4
08-17 15:59:00.701 26720-26920/com.admin.phonedivert W/VideoCapabilities: Unsupported mime video/mp4v-esdp
08-17 15:59:00.720 26720-26920/com.admin.phonedivert I/VideoCapabilities: Unsupported profile 4 for video/mp4v-es
08-17 15:59:00.758 26720-26720/com.admin.phonedivert W/cr_BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 26720
08-17 15:59:00.771 26720-26720/com.admin.phonedivert I/chromium: [INFO:CONSOLE(1)] "Uncaught ReferenceError: content_change is not defined", source: data:text/html; charset=UTF-8,<html>....
08-17 15:59:00.801 26720-26720/com.admin.phonedivert I/chromium: [INFO:CONSOLE(1)] "Uncaught ReferenceError: $ is not defined", source: data:text/html; charset=UTF-8,<!DOCTYPE html><html lang="en"><head><meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" /><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><title>Mobile App</title><link href="assets/css/bootstrap.min.css" rel="stylesheet"><link href="assets/css/style.css" rel="stylesheet"><link href="/css/font-awesome-4.7.0/css/font-awesome.min.css" rel="stylesheet"><style type='text/css'>.button-back {        position: absolute;        z-index: 100;font-size: 49px;width: 45px;color: gray;margin-top: 2px;}.logo{ margin-left: 1px !important; }.mobile-menu {        display:none;        height:30px;        position: relative;        top: -40px;        right: -10px;}.mobile-menu div{        float:left;        width:120px;        height:40px;        background:white;} (1)
08-17 15:59:00.802 26720-26720/com.admin.phonedivert E/chromium: [ERROR:interface_registry.cc(99)] Failed to locate a binder for interface: autofill::mojom::AutofillDriver
08-17 15:59:02.262 26720-26720/com.admin.phonedivert I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@7a4a838 time:33593818

2 个答案:

答案 0 :(得分:0)

此问题归结为网页中的HTML不足。 包含<!DOCTYPE HTML>已解决此问题。 Logcat错误的相关性仍然未知

导致这种情况的另一个问题是使用风格和相对路径。 javascript资源。我有一个webview指向的iframe。由于我直接将HTML加载到视图中,因此视图不知道在哪里查找资源。我想虽然使用loadDataWithBaseUrl()会解决这个问题。但是,这没有。

作为修复,我必须在HTML页面上将所有相对路径更改为静态。

答案 1 :(得分:0)

  

请尝试使用此功能。

webView.loadDataWithBaseURL("",result,"text/html", "UTF-8","");
相关问题