简体   繁体   中英

Android Webview not showing specific page

I'm using a Webview on my app to load a web page. 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>
<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:

    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.

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. getUrlPuntamento() simply returns the URL I'm gonna open.

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.

getUrlPuntamento() returns http://USER:PASSWORD@HOST_IP:PORT/cgi-bin/CGI_GetImage.cgi since the page require basic authentication.

In addition I use webView.setHttpAuthUsernamePassword(HOST, "Embedded-Device", USERNAME, PASSWORD); before loading the url.

and my PuntamentoWebviewClient() has this

@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). Connecting to the configuration page of the device (same authentication, same IP, different CGI) seems to work fine.

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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