question about the native.newWebView

Hi all, 

I have a problem about the native.newWebView.

Please give me some suggestion. Thank you all.

I am trying to use native.newWebView to show local file, but it always show me the error “webpage not found”

The following is my code, please help me.

function save\_html(name,data)     local path = system.pathForFile( name, system.DocumentsDirectory )     local myFile = io.open(path, "wb")     if myFile then         myFile:write( data )         io.close( myFile )     end     local webView = native.newWebView( 0, 0, 320, 480 )     webView:request( name, system.ResourceDirectory )     end  

I use save_html(“page.html”,data) to save file in the device first, parameter data is html text.

It always return “file:///android_asset/page.html” not found

I think maybe the error is caused by I save the file in the wrong path. 

So the second question is how can I change  system.ResourceDirectory?

Thank you again.

Yes, you’re saving to the wrong path.  The ResourceDirectory corresponds to the directory where your project files are located (e.g., main.lua).  Although on your computer you can edit that directory yourself, on the device, it’s read-only.  The DocumentsDirectory is a directory where you can store files that your project creates.  On your computer, you can see it in the Simulator by going to File | Show Project Sandbox.

Thus, since you’re creating the HTML file in the DocumentsDirectory (as you should), your webView should also load the file from the DocumentsDirectory (not the ResourceDirectory).

  • Andrew

thank you Andrew very much.

It works.

Yes, you’re saving to the wrong path.  The ResourceDirectory corresponds to the directory where your project files are located (e.g., main.lua).  Although on your computer you can edit that directory yourself, on the device, it’s read-only.  The DocumentsDirectory is a directory where you can store files that your project creates.  On your computer, you can see it in the Simulator by going to File | Show Project Sandbox.

Thus, since you’re creating the HTML file in the DocumentsDirectory (as you should), your webView should also load the file from the DocumentsDirectory (not the ResourceDirectory).

  • Andrew

thank you Andrew very much.

It works.