webview not loading local HTML files

314 views
Skip to first unread message

ScottDafydd

unread,
Dec 11, 2014, 10:17:35 AM12/11/14
to androi...@googlegroups.com
Hi. I would really welcome any help people might give, as I'm totally at a loss as to what I'm doing wrong. I've created a variable to load a different HTML page depending on which part of a list control is touched (along the lines of var = (item + ".html"). Everything works perfectly when I run it in DroidScript but as an apk, it just gives me the following:

"Web page not available

The Web page at file:///android_asset/user//Html/Audio.html might be temporarily down or it may have moved permanently to a new web address.

Here are some suggestions:

Check to make sure that your device has a signal and data connection
Reload this web page later.

View a cached copy of the web page from Google"

I've tried importing the assets both through dropbox and through the desktop ide, and I've built the apk in both debug and release mode. Still no joy. The funny thing is that I built another app just yesterday using almost the exact same script (different HTML assets) and it works fine!

Chris Hopkin

unread,
Dec 11, 2014, 10:36:52 AM12/11/14
to androi...@googlegroups.com
Hi Scott

It looks like there is an extra forward slash in your url, before Html.

When you call WebView.LoadUrl() make sure there is no leading slash, i.e. it should be WebView.LoadUrl("Html/Audio.html"), not WebView.LoadUrl("/Html/Audio.html").

Hope that helps

Chris

ScottDafydd

unread,
Dec 11, 2014, 12:23:50 PM12/11/14
to androi...@googlegroups.com
Hi Chis, thanks for quick reply but that doesn't seem to be it either. Everything seems to work perfectly within the DroidScript app just not in the apk. I've double checked the capitalisation etc, as I read in the wiki that it's more of an issue within apk's, but can't see anything out of the ordinary. Has anyone else had this issue?

Timo Octazid

unread,
Dec 11, 2014, 12:34:58 PM12/11/14
to androi...@googlegroups.com
Hi,
My first suggestion was the same like these from Chris because you wrote:
file:///android_asset/user//Html/Audio.html
Have you a code example for us?
So we can try it on our devices...
Or is your file saved with another extension like .htm

Many greetings
Timo

Chris Hopkin

unread,
Dec 11, 2014, 12:37:24 PM12/11/14
to androi...@googlegroups.com
Hello

Would you be able to post your spk? We can take a look for you if you like (send it me direct if you'd prefer not to post it on the forum).

Regards

Chris

ScottDafydd

unread,
Dec 11, 2014, 1:58:27 PM12/11/14
to androi...@googlegroups.com
Thanks gentlemen, I'll try both if that's okay. Here is the snippet that seems to be going wrong:


///handles selection of book and loads html file
function menuOptions_OnTouch(item)


    //set up main reading screen and set visibility
    tabs = app.CreateTabs( "READ,LISTEN", 1, 1, "VCenter" );
    layFrm.AddChild( tabs ); 


        //Create tab screen for eBook...
        layRead = tabs.GetLayout( "READ" );
        eBook=app.CreateWebView(1,1);
        eBook.LoadUrl("Html/" + item + ".html");
        layRead.AddChild(eBook);
    
        //Create tab Screen for audiobook
        layListen = tabs.GetLayout( "LISTEN" );
        audioBk=app.CreateWebView(1,1);
        audioBk.LoadUrl("Html/Audio.html");
        layListen.AddChild(audioBk); 


    menuOptions.SetVisibility("Hide");
    tabs.SetVisibility("Show");

}


the Audio.HTML file is just a single page HTML document of links to online pages...

Chris, what's the best way to get the SPK to you?

ScottDafydd

unread,
Dec 15, 2014, 10:59:42 AM12/15/14
to androi...@googlegroups.com
Thought it would be helpful to others to post the solution Chris came up with here in the forum. The main problem was the spaces in the file names that I was trying to load through an OnTouch(item) method. The solution was to rename all my local html files with underscores instead of spaces and then use the following two lines to create a new variable by removing the spaces from the OnTouch(item) selected and replacing them with underscores, as follows:

var book = item.split(' ').join('_');
eBook.LoadUrl("Html/" + book + ".html");

Big thanks to Chris for his help!
Reply all
Reply to author
Forward
0 new messages