local html content not working on android device using native.newWebView

Here’s the code I use for the webView:

local webView

local doc = “yourfile.html”

webView = native.newWebView( 0, display.contentWidth, 320, 480 )
webView.anchorX = 0
webView.anchorY = 0
webView:request( doc , system.ResourceDirectory )

As long as yourfile.html is located in the same directory as main.lua or a subdirectory it should work.

Hi James,

Thanks again for offering your help.

Thats pretty much exactly the code I’m using, although I have the doc in a subdirectory, so its like “language/instructions-en.html” instead of “instructions-en.html”.

Which version of android are you running?

Thanks,

-Aaron

Aaron,
I’m using 4.4.4, on a Galaxy Note 3. There have been numerous other threads about this topic recently. Perhaps someone else has discovered a fix on one of those threads. One thought: I wonder if the - in the html file name is causing the problem?

Jim

yeah, I checked all those threads before writing this one.  I’ll try putting the files into the root dir and see if thats the culprit.

We are experiencing the same issue (using enterprise build 2541).

We use a local html file if there is no internet connection, to show a default webpage. On iOS and the sim this is working fine, but on Android we get the same error that @aisaksen reported. In adb I see this error message:

02-03 10:33:58.718: I/chromium(22764): [INFO:CONSOLE(12)] "Not allowed to load local resource: file:///android\_asset/webkit/android-weberror.png", source: data:text/html,chromewebdata (12)

Having looked on stackoverflow it seems that the error is caused by the webview using 

webview.loadData()

instead of 

webview.loadDataWithBaseURL()

but I’m not sure which of these Corona would use. 

If you’re developing with Corona Enterprise, then you need to double check your AndroidManifest.xml file and make sure that it’s “FileContentProvider” is using your app’s package name.  This is because Corona uses a “content://” URL to access web related files from your app’s “ResourceDirectory”, which can be located under your Android app project’s “assets” directory or within an expansion file.  It should look something like this…

\<provider android:name="com.ansca.corona.storage.FileContentProvider" android:authorities="\<Your.Package.Name\>.files" android:exported="true"/\>

That is, the above element is already in your AndroidManifest.xml, you just need to replace the <Your.Package.Name> with what your app uses.  The exported part does not have to be “true” to display your own internal web pages, but it does need to be true if you’re attaching files mail or using system.openURL() to open files belonging to your app.

We already have that part in our manifest. This is how we currently have it:

\<provider android:name="com.ansca.corona.storage.FileContentProvider" android:authorities="com.quiztix.mygamename.files" android:grantUriPermissions="true" android:exported="true" /\>&nbsp;

I also had to add the grantUriPermissions in order to be able to pass images to an email client - not including it caused the app to crash when the email app opened.

We did have an Android bug with loading HTML assets from the ResourceDirectory in the last release version.  We fixed it in daily build #2526.  So, would you mind double checking if you’re actually using the newest daily build please?  The best way to be sure is to add the following line to you main.lua file…

   print("Corona Build Number = " … system.getInfo(“build”))

You should then see Corona build number via adb logcat, formatted like this:  <Year>:<BuildNumber>

Also, regarding the “grantUriPermissions” attribute, I don’t recall that be needed when I tested it.  The “exported” attribute was always enough.  Can you tell me what device model, Android OS version, and mail app (Gmail?) that it crashed on please?  Thanks.

Oh and one more thing regarding checking the build #.  Try doing a “clean” build by typing the following in your Android app project directory via the Terminal…

   ant clean

This is in case you are running into an “incremental build” issue with Google’s Android SDK.  The idea is that if you upgrade to a newer Android library version, such as Corona, then you should do a clean build to ensure that the new changes are actually compiled in.

We’re not using the latest version, but we’re using 2541 which is later than 2526. Not using the latest because notifications were moved to a plugin, and we’re too close to submission to change + test that part of the app.  

‘ant clean’ gets run in the project at least every few days, and was done earlier this morning so I don’t think that can be the cause.

Hold on.  I think we’re talking about a different issue.  In your case, does it fail to load a local HTML file if you do *not* have an internet connection?

I ask because loading a local HTML files local assets (JPEGs, PNGs, CSS files, etc.) works fine for me.  I tested relative paths “.” and “…” and it worked fine.  I confirmed that I can load images from different directories too by using relative paths in my HTML like this…

   ./Image1.png

   …/Image2.png

   …/Images/Image3.png

   Subdirectory/Image4.png

I even tried linking/loading a stylesheet via “…/Stylesheets/style.css” and it worked too.  So, I’m kind of scratching my head as to why it’s not working for you.

Yes it fails when we do *not* have an internet connection, when loading a local HTML file.  

We’re a bit confused too. We see the same error message in the webview that the original post did:

"webpage not available

 

the webpage at content://com.quiztix.mygamename.files/assets/cachedpage.html could not be loaded because

 

net::ERR_UNKNOWN_URL_SCHEME

"

 

where cachedpage.html is the local html file we use. It’s being put into the assets folder of the android project when building the apk, as expected.

 

I’m not at my desk to double check what happens if I try to load the same local page while we do have an active internet connection (currently it loads a genuine webpage from our server when it has a connection).

Any other ideas from anyone on what could be causing this to fail?

Sorry Joshua I forgot to say that I tested out loading the local page while device is online, and exactly the same thing happens.

yes, i can confirm that my issue happens no matter if i’m online or offline

We’re not able to reproduce the issue that you guys are seeing.  So, the next step is to send us a project which can reproduce this issue.  You can do so by clicking the “Report a Bug” link at the top of this web page.  Also, make sure to indicate the Corona build number you are using, if this is only happening to you with Corona Enterprise (is this true?), and the Android device model this is happening on.  Thanks!

Ok, we have dropped using the cached webview while offline for now, as we simply don’t have the time to wait for the fix.

If things calm down a bit then I will try to create a test project and submit it, but if anyone else is able to do the same before then it would be appreciated.

yeah, unfortunately I’m in the same boat as Alan – I need the bug fixed, but I don’t have the two hours to make a whole new enterprise project, make sure it runs on device, and upload it, just to show that indeed it doesn’t work.  (Thats really the biggest challenge with the current “submit a bug” system – it puts a huge amount of work on the developer, which works for developers that are paid a salary, but not so much for small indie teams.)

I just have the same issue when I load a html from system.ResourceDirectory with webview compiled by enterprise 2015.2574

What’s wrong?

I ran into the no-image-loading bug for local HTML content in the resource directory before. But I can confirm using daily build 2015.2574 (Corona SDK, not Enterprise) it works fine for me. Both images and HTML text.