0

I'm building an app that is dependend on WebViews to render HTML-files in the assets folder. These files contain Javascript. The app works perfectly on my own device, including all the Javascript. But the Android emulator from Android Studio executes only some of the Javascript, on some of the pages. And the device from one of the testers shows blank pages instead of the HTML-files. And the device from another one of our testers also doesn't execute all the Javascript properly.

So, I'm not really sure what to do here. All pages are loaded with the exact same WebView-method and most of the Javascript is also similar. I can't debug or release an app that behaves differently on each device.

The code to load the WebViews:

    WebView myWebView = (WebView) findViewById(R.id.webview);
    myWebView.addJavascriptInterface(new WebAppInterface(this), "Android");
    WebSettings webSettings = myWebView.getSettings();
    CookieManager.getInstance().setAcceptCookie(true);
    webSettings.setJavaScriptEnabled(true);
    webSettings.setAllowFileAccessFromFileURLs(true); 
    webSettings.setAllowUniversalAccessFromFileURLs(true);
    webSettings.setAllowFileAccess(true);
    webSettings.setAllowContentAccess(true);
    webSettings.setDomStorageEnabled(true);
    webSettings.setLoadWithOverviewMode(true);
    myWebView.setWebChromeClient(new WebChromeClient() {
        public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
            callback.invoke(origin, true, false);
        }
    });
    myWebView.loadUrl("file:///android_asset/www/file.html");

    myWebView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
            view.loadUrl(request.toString());
            return true;
        }
    });

Once again, the app works perfectly on my own Android device. Even after I reinstalled it. I just don't see why it wouldn't work on other devices. Does someone have a solution or explaination?

Jan Hoi
  • 61
  • 1
  • 9
  • 1
    Maybe the webview isn't updated – Zoe May 15 '17 at 15:22
  • also if you are using proguard then [check here](http://stackoverflow.com/questions/17629507/how-to-configure-proguard-for-javascript-interface) (blind guess/suggestion) – snachmsm May 15 '17 at 15:24
  • And what you saw inside Android logs from simulator and/or problematic devices ? – Anton Malmygin May 15 '17 at 15:42
  • @LunarWatcher Would that explain why it works so random? And how do I update the webview? – Jan Hoi May 15 '17 at 15:44
  • @snachmsm I'm not, but thanks for the suggestion – Jan Hoi May 15 '17 at 15:44
  • @AntonMalmygin I'm not really sure how I could check the logs of the problematic devices, since I do not physically have them. And the emulator gives a different log than executing the app on your own device in Android Studio, and I can't find the option to change that so that you can see helpful logs from the emulator – Jan Hoi May 15 '17 at 15:46

1 Answers1

1

I advice you to use the WebView Remote Debugging,so that you can see the source code that running in the WebView of your html file,and then you can click the web page in you Chrome Browser to see how the page react. That is the way I took when I met some problem in webview.

all you need to do is just run the following code

if (Build.VERSION.SDK_INT >= 19){
     WebView.setWebContentsDebuggingEnabled(true);
}

or you can find more detail about remote-debugging