Commit 82515606 by mergen

增加了js加载mimeType。

parent 1a3a16d5
...@@ -46,6 +46,9 @@ import java.io.FileNotFoundException; ...@@ -46,6 +46,9 @@ import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.util.Hashtable; import java.util.Hashtable;
import java.io.IOException;
import java.io.InputStream;
/** /**
* This class is the WebViewClient that implements callbacks for our web view. * This class is the WebViewClient that implements callbacks for our web view.
...@@ -68,6 +71,66 @@ public class X5WebViewClient extends WebViewClient { ...@@ -68,6 +71,66 @@ public class X5WebViewClient extends WebViewClient {
this.parentEngine = parentEngine; this.parentEngine = parentEngine;
} }
@Override
public WebResourceResponse shouldInterceptRequest(WebView webView, WebResourceRequest request , Bundle bundle) {
String url = request.getUrl().toString();
if (url.contains(".js")){
//干掉file:///
String newUrl = url.replace("file:///", "");
Log.d("new" , newUrl);
//vendor-es2015.js
String rootDir = "www";
String mimeType = "";
String encoding = "utf-8";
//文件名判断bug
if (newUrl.contains("es2015")){
mimeType = "application/javascript";
}else{
mimeType = "text/javascript";
}
String fileName = rootDir + "/" + newUrl;
try {
InputStream is = this.activity.getAssets().open(fileName);
Log.e("file" , "------ File loaded ---000-0-------------");
return new WebResourceResponse(mimeType, encoding, is);
} catch (IOException e) {
Log.e("file" , "文件美欲呕找到");
e.printStackTrace();
}
}
if (url.contains(".png") || url.contains(".svg")){
String newUrl = url.replace("file:///", "");
Log.d("new" , newUrl);
String rootDir = "www";
String mimeType = "image/*";
String encoding = "utf-8";
String fileName = rootDir + "/" + newUrl;
try {
InputStream is = this.activity.getAssets().open(fileName);
return new WebResourceResponse(mimeType, encoding, is);
} catch (IOException e) {
}
}
return super.shouldInterceptRequest(webView, request);
}
/** /**
* Give the host application a chance to take over the control when a new url * Give the host application a chance to take over the control when a new url
* is about to be loaded in the current WebView. * is about to be loaded in the current WebView.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment