2

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?

Mohammad Ersan
  • 12,304
  • 8
  • 54
  • 77
  • Hi, I'm now facing a similar problem with my WebView. http://stackoverflow.com/questions/18799880/google-code-prettify-js-not-working-in-ics-webview . You found any other solution for this problem ? – niranjan94 Sep 16 '13 at 13:19
  • no i didn't, try the above solution – Mohammad Ersan Sep 16 '13 at 15:22

3 Answers3

1

the only solution I found is the same as the question....

Mohammad Ersan
  • 12,304
  • 8
  • 54
  • 77
0

Might be a stupid thing i'm saying here. But it's late and i'm tired ...

Have you tried enabling Javascript in the WebView?

WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
AndreiBogdan
  • 10,858
  • 13
  • 58
  • 106
0

u can add one property android:hardwareAccelerated="true" in application tag of your manifest.xml as well u can add some settings in on create

wvMain.getSettings().setSupportZoom(true);
      wvMain.getSettings().setBuiltInZoomControls(true);
      wvMain.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
      wvMain.setScrollbarFadingEnabled(true);
      wvMain.getSettings().setLoadsImagesAutomatically(true);
      wvMain.getSettings().setJavaScriptEnabled(true);
      wvMain.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
       wvMain.getSettings().setPluginsEnabled(true);
         wvMain.getSettings().setSupportZoom(false);     

         wvMain.getSettings().setCacheMode(wvMain.getSettings().LOAD_NO_CACHE);
         webSettings8.setPluginState(WebSettings.PluginState.ON);
         wvMain.setWebViewClient(new WebViewClient());
         wvMain.addJavascriptInterface(this, "Android");
         wvMain.getSettings().setSupportMultipleWindows(true);
         wvMain.getSettings().setPluginsEnabled(true);
         wvMain.getSettings().setUseWideViewPort(true);
         wvMain.getSettings().setLoadWithOverviewMode(true);

i hope this helps.but note, hardwareaccelerated property supports after 3.0.

CodingDecoding
  • 433
  • 2
  • 9
  • 20
  • most of what you said are enabled, but some of them like zoom and wideView i don't need, and still the same. – Mohammad Ersan Sep 24 '12 at 13:31
  • OK..well it don't happen generally. I suggest check your log cat. You will get to know on which line of your code the error is coming. May be it can be any null value or something. – CodingDecoding Sep 25 '12 at 05:15
  • There is one more option you can use broadcast receiver..I think this will definitely can help you – CodingDecoding Sep 25 '12 at 05:57