0

I'm dealing with the following problem:

I have a webview inside an activity:

webView = (WebView) findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDatabaseEnabled(true);
webView.getSettings().setBuiltInZoomControls(false);
webView.getSettings().setSupportZoom(false);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
webView.setScrollbarFadingEnabled(false);

webView.setWebViewClient(new HelloWebViewClient());
System.out.println("percorso" + path.toString());
url.setText(path.toString()); 
webView.loadUrl("local path of my html file" .....\..\..page.htm);

private class HelloWebViewClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);
        return true;
    }
}

This is the app I'd like to run locally offline: http://miniapps.co.uk/checklist/ If I open the browser and i go to the link above everything works fine, so the android browser is actually able to run it.

Now I have downloaded this app and I stored it in a folder on my sd card: download/myapp in the folder I have the html file: check_list.htm and a folder (check_list files) with the javascript files needed to run it.

But when i open it inside my webview, the page is correcty loaded but doesn't work...i can't click on buttons and other elements, i can't actually interact with it....

I thought it could be a problem related to my webview settings so i used astro file manager to surf into my sd card, i clicked on check_list.htm, i chose html viewer and i got the same issues....

So I downloaded opera mobile, and i did the same but this time I opened it with opera and now it's working correctly.

Do you know why? How can I fix the problem? Am I missing some settings on my webview or is the webview\android broser that hase some problems opening locally stored html pages and running linked javascript files?

EDIT If I open the android browser and I write the path of the HTML file, it works. I have to do it manually cause if I click on the HTML file, android browser it's not an option......so in the end it works both on android browser and opera, and it doesn't with HTML viewer and my web view.....so I'm missing some settings cause the web view should have the same features of the android browser....shouldn't it?

Jav_Rock
  • 22,059
  • 20
  • 123
  • 164
Sgotenks
  • 1,723
  • 4
  • 20
  • 34
  • JavaScript alerts are sent to the WebClient. Catch them there to gather more information on the error(s). – rds Jan 30 '12 at 13:36
  • 1
    No, the webview doesn't have the same features, until you have fully implemented the attached `WebClient`. – rds Jan 30 '12 at 14:22
  • Tnx any link or idea about the one i should implement to fix it? – Sgotenks Jan 30 '12 at 14:39
  • Question is: do you really need a webview? Why don't you send an intent to display the local file? – rds Jan 30 '12 at 14:55
  • Ok but i need to display it inside my app.....that basically is an applilcatione running webapp stored locally.....What could runt it but webview or a browser?Can i embed android browser instead to use a webview? – Sgotenks Jan 30 '12 at 15:07
  • @user280560 Did you ever find a solution, I am also facing exact issue? – Rahul Choudhary Mar 03 '12 at 18:53

2 Answers2

0

If "doesn't run" mean it does not open new windows, that's because you need to specify the webview client.

From the Javadoc for WebView

By default, requests by the HTML to open new windows are ignored. This is true whether they be opened by JavaScript or by the target attribute on a link. You can customize your WebChromeClient to provide your own behaviour for opening multiple windows, and render them in whatever manner you want.

See https://stackoverflow.com/a/3847016/94363 or rtfm...

Community
  • 1
  • 1
rds
  • 26,253
  • 19
  • 107
  • 134
  • No i don't have to open new windoes, the one linked above is a web app not a web page. It means that it shows the page correctly, that basically is an empty list, then when i write down a new item into a textbox and i click ADD to add it to the list i can't.....the button does't work, i can't even press it....and it's the same with other buttons...and it's the same with others application, i can't interact with some elements (maybe a problem using .js files sored locally??) – Sgotenks Jan 30 '12 at 12:20
0

Please confirm before, your local file is inside asset/www/index.html directory.

Akilan
  • 1,707
  • 1
  • 16
  • 30
  • No, is on my sd card not inside the project......i thought that including a webwiew inside an activity i got the some features of the android browser.....but i don't i need to add something to my code (but i don't know what is missing), or embed the android browser directly :) – Sgotenks Jan 30 '12 at 14:41