当indel.html里含有 <img src=\"http://。。。网络地址。。。"/> 时,运行时地址就变成了 file://http://。。。网络地址。。。,怎么去掉“file://”呢?
4 个解决方案
#1
<img src=\"http:// 这部分的\是干嘛用的?去掉看看
#2
图片的网络地址
#3
没人吗???
#4
已解决,webview里有一个方法,shouldInterceptRequest ,
webView.setWebViewClient(new WebViewClient(){
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
Log.i("LOGTAG", "shouldInterceptRequest url=" + url + ";threadInfo" + Thread.currentThread());
WebResourceResponse response = null;
if (url.contains("判断条件")) {
try {
URL u= new URL(url.replace("file:///","").replace("%22",""));//把file://替换掉
HttpURLConnection conn = (HttpURLConnection)u.openConnection();
InputStream inputStream = conn.getInputStream();
response = new WebResourceResponse("image/png", "UTF-8", inputStream);
} catch (IOException e) {
e.printStackTrace();
}
}
return response;
}
});
webView.loadUrl("file:///android_asset/test.html");
webView.setWebViewClient(new WebViewClient(){
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
Log.i("LOGTAG", "shouldInterceptRequest url=" + url + ";threadInfo" + Thread.currentThread());
WebResourceResponse response = null;
if (url.contains("判断条件")) {
try {
URL u= new URL(url.replace("file:///","").replace("%22",""));//把file://替换掉
HttpURLConnection conn = (HttpURLConnection)u.openConnection();
InputStream inputStream = conn.getInputStream();
response = new WebResourceResponse("image/png", "UTF-8", inputStream);
} catch (IOException e) {
e.printStackTrace();
}
}
return response;
}
});
webView.loadUrl("file:///android_asset/test.html");
#1
<img src=\"http:// 这部分的\是干嘛用的?去掉看看
#2
图片的网络地址
#3
没人吗???
#4
已解决,webview里有一个方法,shouldInterceptRequest ,
webView.setWebViewClient(new WebViewClient(){
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
Log.i("LOGTAG", "shouldInterceptRequest url=" + url + ";threadInfo" + Thread.currentThread());
WebResourceResponse response = null;
if (url.contains("判断条件")) {
try {
URL u= new URL(url.replace("file:///","").replace("%22",""));//把file://替换掉
HttpURLConnection conn = (HttpURLConnection)u.openConnection();
InputStream inputStream = conn.getInputStream();
response = new WebResourceResponse("image/png", "UTF-8", inputStream);
} catch (IOException e) {
e.printStackTrace();
}
}
return response;
}
});
webView.loadUrl("file:///android_asset/test.html");
webView.setWebViewClient(new WebViewClient(){
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
Log.i("LOGTAG", "shouldInterceptRequest url=" + url + ";threadInfo" + Thread.currentThread());
WebResourceResponse response = null;
if (url.contains("判断条件")) {
try {
URL u= new URL(url.replace("file:///","").replace("%22",""));//把file://替换掉
HttpURLConnection conn = (HttpURLConnection)u.openConnection();
InputStream inputStream = conn.getInputStream();
response = new WebResourceResponse("image/png", "UTF-8", inputStream);
} catch (IOException e) {
e.printStackTrace();
}
}
return response;
}
});
webView.loadUrl("file:///android_asset/test.html");