Android Question how can I laod html file from sdcard ?

khosrwb

Active Member
Licensed User
I will open html file from sdcard
by this code:
WebView1.LoadUrl("file://"&File.Combine(File.dirrootexternal,"1.htm"))

but when use this code
show me this error
Capture1.PNG



no idea for my problem
excuse me for my bad english language:oops:
 
Last edited:

NJDude

Expert
Licensed User
Try this:
B4X:
Private myHTML As String

myHTML = File.ReadString(File.DirRootExternal, "1.html")

WebView1.LoadHtml(myHTML)
 

NJDude

Expert
Licensed User
The ZIP file contains the source code, but, it's missing the "1.html" file, the code I posted before should work as long as the HTML EXISTS on the device.
 

khosrwb

Active Member
Licensed User
excuse me
this code is here :
This error is displayed when I compile the code with (( F5 or Ctrl+3 ))
but when I use (( Ctrl+2 )) to compile this code there isn't problem
 

Attachments

Last edited:

NJDude

Expert
Licensed User
Just to prove that the code I posted works, see the attached sample.

Note that if you want to use DirRootExternal, you have to copy the HTML to that location BEFORE you read it, the sample I attached just shows you how to read an HTML saved on the device and display it on a WebView.
 

Attachments

khosrwb

Active Member
Licensed User
hi NJDude
I run your sample code
but This error is displayed :
I do not know what this error means there
 

Attachments

khosrwb

Active Member
Licensed User
thanks but
I will save the html files on the sdcard and then load html file from sdcard by app
 

Mahares

Well Known Member
Licensed User
Since your file is in the sdcard, simply replace this line:
B4X:
myHTML = File.ReadString(File.DirAssets, "1.html")
with this in NJDude's sample program:
B4X:
myHTML = File.ReadString(File.DirRootExternal, "1.html")
 

Mahares

Well Known Member
Licensed User
If you comment the Do While True line and the Loop line, your code will work. I think the reason you are getting the 'Unreachable' statement is because when you issue the following command: FD.FilePath = InitialFilePath, it initially sets the chosen file name to a blank string, so the condition is never True.
 
Top