Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]

native.newWebView - Error loading local files - system.ResourceDirectory
Started by Luiz H. Lugato Jun 30 2019 05:49 AM

1 reply to this topic
webview html file android
This topic has been archived. This means that you cannot reply to this topic.
[TOPIC: post.html]

Luiz H. Lugato

[GLOBAL: userInfoPane.html]
Luiz H. Lugato
  • Observer

  • 8 posts
  • Corona SDK

Hi to all, 


I'm trying to load a html using the native.newWebView, the file are stored in a system.ResourceDirectory like "data/dirname" and the file name is "US.html".


In Corona Simulator the file are loaded correctly, but when I try in a Android device I get a error :


Not possible to load a web page from address:

content://[package name].files/assets/data/dirname/US.html



If anyone have a hint to help me I appreciate :)



[TOPIC: post.html]

Luiz H. Lugato

[GLOBAL: userInfoPane.html]
Luiz H. Lugato
  • Observer

  • 8 posts
  • Corona SDK

Hi to all again,


I solved the problem, in the pathForFile Documentation API there's this explanation :


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.lua.m4v.mp4.png.jpg, and .ttf.


Because of this limitation, if you have files of these types bundled in the core directory that you need to copy to another directory, you must change the file name so it can be accessed by the file I/O APIs. For example, if you want to move cat.png from the resource directory to the documents directory, it must be renamed cat.png.txt to be copied. See the Reading and Writing Files guide for more information and examples.

So ..
First :
- Rename the files that you need be read with a txt extension ex: help.html to help.html.txt
Check if the file that I need to load in the webview, exist in system.DocumentsDirectory with system.pathForFile( fname, path ) command.
- If the file doesn't exist, copy the help.html.txt that exist in system.ResourceDirectory to system.DocumentsDirectory using two io.open command, one to read the file that will be copied and another to copy the content to system.DocumentsDirectory excluding the txt extension.
If anyone need some help please contact me