Webview not working with local files

I am working on an EMS app for our hospital on ANDROID and I am displaying a list of files and then allowing the user to choose one and it displays an html file with the neccessary protocol, drug information, etc.

I currently have it displaying a webpage in a webview that takes up part of the screen - when they hit the back button, I have it removing the webview - otherwise it sticks around.

So far, so good.

BUT… when I try to display a local file, it can’t find the local file.

I’ve copied all of the files to a directory called HTML and copied that into my corona directory and added that to my project.

So, in my directory, it looks like this:

C:\CoronaProjects\ProjectDirectory\HTML

Under HTML, is a directory called Drugs, under which is a file called Aspirin.html

I am using the following code:

 local doc = "HTML/Drugs/Aspirin.html" webView = native.newWebView( 0, SBH, \_W, \_H-SBH ) webView.anchorX = 0 webView.anchorY = 0 webView:request( doc, system.ResourceDirectory )

So, to me, it looks like it should be looking for HTML\Drugs\Aspirin.html in the resource directory (where main.lua is located).  According to that, it SHOULD exist.

Is there some reason why this won’t work?  I can’t troubleshoot it in the simulator since webview doesn’t work there.

Any ideas?

Corona allows direct loading of images and audio files using the appropriate APIs, but it has limited access to resource files on Android using the file I/O APIs. Specifically, the following types can not be read from the resources directory: .html, .htm., .3gp, .m4v, .mp4, .png, .jpg, and .ttf.

http://docs.coronalabs.com/api/library/system/ResourceDirectory.html

John, 

Scratch what’s written above, as I’ve found it is inaccurate. I used your code and had no issue reading a webView just as you posted it. This code works for me:

local doc = "HTML/Drugs/Aspirin.html" webView = native.newWebView( 0, SBH, \_W, \_H-SBH ) webView.anchorX = 0 webView.anchorY = 0 webView:request( doc, system.ResourceDirectory )

I created a simple “Aspirin.html” file, put it in the exact folder structure you did. I built this and deployed on my Note 3 with no issues. Not sure where that leaves you. The only thing I can think of is 1.) there may be a case error in your folder structure. 2.) This is a bug in the current Public build. 

I found the issue.  In the database, there were spaces after the name, so it was actually trying to load Aspirin .html instead of Aspirin.html.  It did a trim on it and that fixed the issue.  I have no idea why they were entered into the database with extra spaces.

Thanks!

Corona allows direct loading of images and audio files using the appropriate APIs, but it has limited access to resource files on Android using the file I/O APIs. Specifically, the following types can not be read from the resources directory: .html, .htm., .3gp, .m4v, .mp4, .png, .jpg, and .ttf.

http://docs.coronalabs.com/api/library/system/ResourceDirectory.html

John, 

Scratch what’s written above, as I’ve found it is inaccurate. I used your code and had no issue reading a webView just as you posted it. This code works for me:

local doc = "HTML/Drugs/Aspirin.html" webView = native.newWebView( 0, SBH, \_W, \_H-SBH ) webView.anchorX = 0 webView.anchorY = 0 webView:request( doc, system.ResourceDirectory )

I created a simple “Aspirin.html” file, put it in the exact folder structure you did. I built this and deployed on my Note 3 with no issues. Not sure where that leaves you. The only thing I can think of is 1.) there may be a case error in your folder structure. 2.) This is a bug in the current Public build. 

I found the issue.  In the database, there were spaces after the name, so it was actually trying to load Aspirin .html instead of Aspirin.html.  It did a trim on it and that fixed the issue.  I have no idea why they were entered into the database with extra spaces.

Thanks!