Android Question how can I laod html file from sdcard ?

khosrwb

Active Member
Licensed User
Longtime 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
Longtime User
Try this:
B4X:
Private myHTML As String

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

WebView1.LoadHtml(myHTML)
 
Upvote 0

NJDude

Expert
Licensed User
Longtime 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.
 
Upvote 0

khosrwb

Active Member
Licensed User
Longtime 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

  • readhtml.zip
    7.7 KB · Views: 99
Last edited:
Upvote 0

NJDude

Expert
Licensed User
Longtime 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

  • Sample.zip
    10.7 KB · Views: 104
Upvote 0

khosrwb

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

Attachments

  • Capture5.PNG
    Capture5.PNG
    256.6 KB · Views: 104
Upvote 0

khosrwb

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

Mahares

Expert
Licensed User
Longtime 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")
 
Upvote 0

khosrwb

Active Member
Licensed User
Longtime User
thanks Mahares
thanks for all the help and attention:)
but I don't know why my app show this error:confused::confused::confused:
 

Attachments

  • Capture6.PNG
    Capture6.PNG
    177.6 KB · Views: 97
  • Capture7.PNG
    Capture7.PNG
    176.1 KB · Views: 104
  • readhtml.zip
    7.7 KB · Views: 102
Last edited:
Upvote 0

Mahares

Expert
Licensed User
Longtime 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.
 
Upvote 0
Top