這裏是工作的例子,獲取HTML作爲字符串,它是在webview中加載的,以及在將圖像url轉換爲位圖後如何從中獲取圖像URL。
集的WebView客戶端的網頁視圖像
webview.setWebViewClient(new WebClientClass());
web視圖客戶端下面
public class WebClientClass extends WebViewClient {
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
if (progressDialog != null && progressDialog.isShowing())
progressDialog.dismiss();
wvAboutUs.evaluateJavascript(
"(function() { return ('<html>'+document.getElementsByTagName('html')[0].innerHTML+'</html>'); })();",
new ValueCallback<String>() {
@Override
public void onReceiveValue(String html) {
JsonReader reader = new JsonReader(new StringReader(html));
reader.setLenient(true);
try {
if (reader.peek() != JsonToken.NULL) {
if (reader.peek() == JsonToken.STRING) {
String msg = reader.nextString();
if (msg != null) {
Log.d("HTML", msg);
Pattern p = Pattern.compile("src=\"(.*?)\"");
Matcher m = p.matcher(msg);
if (m.find()) {
Log.d("HTML", m.group(1)); // This will print your image url
}
}
}
}
} catch (IOException e) {
Log.e("TAG", "MainActivity: IOException", e);
} finally {
try {
reader.close();
} catch (IOException e) {
}
}
}
});
}
}
給你有圖像完整的網絡路徑? –
你只是想在webview上顯示圖像? –
@SohailZahid是的,圖像完整的網絡路徑是:https://sapsnkra.moe.gov.my/randomimage.php – nerdcomp1