简体   繁体   English

Android Webview未显示特定页面

[英]Android Webview not showing specific page

I'm using a Webview on my app to load a web page. 我在我的应用程序上使用Webview加载网页。 Other web pages are working fine, this one seems to load but then showing a blank page. 其他网页运行正常,该网页似乎已加载,但随后显示空白页。

The source code of the html page is generated by a CGI and the output is: html页面的源代码由CGI生成,输出为:

<html>
<head>
<meta name="viewport" content="width=device-width; height=device-height;">
<link rel="stylesheet" href="resource://gre/res/ImageDocument.css">

/*
 * This CSS stylesheet defines the rules to be applied to any ImageDocuments,
 * including those in frames.
*/

@media not print {
  .overflowing {
    cursor: zoom-out;
  }

  .shrinkToFit {
    cursor: zoom-in;
  }
}

@media print {
  img {
    display: block;
  }
}
</link>
<link rel="stylesheet" href="resource://gre/res/TopLevelImageDocument.css">

@media not print {
  body {
    margin: 0;
  }

  img {
    text-align: center;
    position: absolute;
    margin: auto;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
  }

  .completeRotation {
    transition: transform 0.3s ease 0s;
  }
}

img {
  image-orientation: from-image;
}
</link>
<link rel="stylesheet" href="chrome://global/skin/media/TopLevelImageDocument.css">
Filtered chrome url chrome://global/skin/media/TopLevelImageDocument.css
</link>
<title>CGI_GetImage.cgi (immagine JPEG, 640 × 480 pixel) - Riscalata (86%)</title>
</head>
<body>
<img class="shrinkToFit" src="PATH_TO_IMAGE" alt="" width="553" height="415">
</body>
</html>

In my app I load the url using this settings to my Webview: 在我的应用程序中,使用以下设置将URL加载到Webview中:

    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setLoadWithOverviewMode(true);
    webSettings.setUseWideViewPort(true); // Alstro tried without this...

I think it might be some kind of problem with the CSS of the page but unfortunately I CAN NOT edite the output of the CGI generating the html. 我认为页面的CSS可能存在某种问题,但不幸的是,我无法编辑生成html的CGI的输出。

Any help? 有什么帮助吗?

EDIT: 编辑:

Here's how I load the URL: 这是我加载网址的方式:

webView = (WebView)findViewById(R.id.webViewPuntamento);
webView.setWebViewClient(new PuntamentoWebviewClient());
webView.loadUrl(getUrlPuntamento());

where PuntamentoWebviewClient() is an extension of WebviewClient wich handles both basic http authentication and connection errors received from the server. 其中PuntamentoWebviewClient()PuntamentoWebviewClient()的扩展,它处理基本的HTTP身份验证和从服务器收到的连接错误。 getUrlPuntamento() simply returns the URL I'm gonna open. getUrlPuntamento()只是返回我要打开的URL。

Fact is I can load and see any other pages, except this one. 事实是,我可以加载并查看除该页面以外的任何其他页面。 I get no errors and I can show by a Toast the title of the loaded page, but no contents. 我没有收到任何错误,并且可以通过Toast显示已加载页面的标题,但没有内容。

getUrlPuntamento() returns http://USER:PASSWORD@HOST_IP:PORT/cgi-bin/CGI_GetImage.cgi since the page require basic authentication. 由于页面需要基本身份验证,因此getUrlPuntamento()返回http://USER:PASSWORD@HOST_IP:PORT/cgi-bin/CGI_GetImage.cgi

In addition I use webView.setHttpAuthUsernamePassword(HOST, "Embedded-Device", USERNAME, PASSWORD); 另外,我使用webView.setHttpAuthUsernamePassword(HOST, "Embedded-Device", USERNAME, PASSWORD); before loading the url. 在加载网址之前。

and my PuntamentoWebviewClient() has this 和我的PuntamentoWebviewClient()有这个

@Override
public void onReceivedHttpAuthRequest(WebView view, @NonNull HttpAuthHandler handler, String host, String realm) {
   handler.proceed(USERNAME, PASSWORD);
}

The CGI is on an embedded device wich I try to contact by direct connection to its wifi (this connection works fine). CGI在嵌入式设备上,我尝试通过直接连接到其wifi来联系它(此连接工作正常)。 Connecting to the configuration page of the device (same authentication, same IP, different CGI) seems to work fine. 连接到设备的配置页面 (相同的身份验证,相同的IP,不同的CGI)似乎可以正常工作。

For future me (or anyone else who might fall in this issue): the problem was that the CGI returned only the image, not an HTML page with the image in it. 为了将来我(或其他可能遇到此问题的人):问题是CGI仅返回图像,而不返回其中包含图像的HTML页面。 The misunderstanding araised because the browser wrapped the image in an HTML page... In the end there's no need to use a WebView but just an AsyncTask to grab the image and show it. 误解之所以引起,是因为浏览器将图像包装在HTML页面中...最终,无需使用WebView,而只需使用AsyncTask即可捕获图像并显示它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM