2017-08-17 143 views
0

我試圖更加聰明,通過AsyncTask使用HttpUrlConnection將網頁加載到WebView中。 以前我用WebView的.loadurl()WebView,無法正確加載html

我已經測試http://www.google.co.uk,這似乎工作正常。 我從日誌中得到以下輸出,不幸的是我無法確定加載此特殊頁面時的實際問題。

我不能想象的是爲什麼它談論音頻/視頻編解碼器是或不支持。網頁沒有任何與這些todo。

當加載HTML到web視圖,我使用:

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: [email protected] time:33593818 

回答

0

這個問題是由於網頁中的HTML不足造成的。 包括<!DOCTYPE HTML>得到了解決。 Logcat錯誤仍然未知相關

導致此問題的另一個問題是使用相對路徑爲樣式& JavaScript資源。我有一個webview指向的iframe。因爲我直接將HTML加載到視圖中,所以視圖不知道在哪裏查找資源。我會雖然使用loadDataWithBaseUrl()將解決這個問題。但是,這並沒有。

作爲修復,我不得不將所有相對路徑更改爲我的HTML頁面上的靜態。

0

請嘗試使用本。

webView.loadDataWithBaseURL("",result,"text/html", "UTF-8","");