Issue
I am working on EPUB reader for the company using JavaScript, the application runs well on Android 2.2, but when i try it on ICS & HoneyCom, the JavaScript doesn't work well. The first problem i faced, the WebView
doesn't load JS files (Unknown Error -6
), so i used this solution:
@TargetApi(11)
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
Log.d("shouldInterceptRequest", url);
InputStream stream = inputStreamForAndroidResource(url);
if (stream != null) {
return new WebResourceResponse("text/javascript", "utf-8", stream);
}
return super.shouldInterceptRequest(view, url);
}
private InputStream inputStreamForAndroidResource(String url) {
final String ANDROID_ASSET = "file:///android_asset/";
if (url.contains(ANDROID_ASSET)) {
// url = url.replaceFirst(ANDROID_ASSET, "");
String[] f = url.split("/");
url = "epub/"
+ f[f.length - 1]
.substring(0, f[f.length - 1].indexOf("'"));
try {
AssetManager assets = mActivity.getAssets();
Uri uri = Uri.parse(url);
return assets
.open(uri.getPath(), AssetManager.ACCESS_STREAMING);
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
and now i don't have this error, but the JS still doesn't work. Does anyone have a solution?
Solution
the only solution I found is the same as the question....
Answered By - Mohammad Ersan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.