Android Question Webview display from Assets

casher2

Member
Licensed User
Longtime User
Copied simple one line [test.html] to Files with Add File.

Load Layout with one view [WebView1]

Command: WebView1.LoadUrl("file:///android_asset/test.html") gives the following error:

file:///android_asset/test.html could not be found.

(there are no problems with the html file, itself)

Hate asking these beginner questions, but that's what I am!

Thanks
 

eurojam

Well-Known Member
Licensed User
Longtime User
The Android file system is case sensitive. best to control if your file is realy test.html and not Test.html...
 
Upvote 0

casher2

Member
Licensed User
Longtime User
File is all lower case. I've tried various HTMLfiles, all work in browser and if I use Webview1.LoadHTML with the HtML text, it loads fine. Just won't find the file in Assets.
Is it as simple as copying the file to [Files]?
Thanks for reply.
 
Upvote 0

casher2

Member
Licensed User
Longtime User
I stumbled across a solution. Don't know why previous didn't work but this does:

File.Copy(File.DirAssets, "test.html", File.DirDefaultExternal, "test.html")
WebView1.LoadUrl("file://" & File.Combine(File.DirDefaultExternal, "test.html"))

Obviously, the test.html does exist or copy file wouldn't work so still puzzled by 'not found error' reported above.

Still interested in answer if anyone could explain.
 
Upvote 0

An Schi

Well-Known Member
Licensed User
Just a noob myself, so i am also guessing

Try:

WebView1.LoadUrl(File.DirAssets, "test.html")
 
Upvote 0

casher2

Member
Licensed User
Longtime User
Just a noob myself, so i am also guessing

Try:

WebView1.LoadUrl(File.DirAssets, "test.html")

Gave it a shot. Had to change slightly due to syntax error (needs all in quotes): WebView1.LoadUrl("File.DirAssets,test.html")

Got the same error but thanks for the effort/idea. Would guess there's a simple answer but these noob questions seem to get little response from the experts...too bad.
Surely been answered before somewhere but specifics are very hard to find, for me at least.
 
Upvote 0

An Schi

Well-Known Member
Licensed User
Nood questions DO get response here. Trust me!

I think i solved it. See the code here and take care of the #DebuggerForceStandardAssets: true here. See also the attached projetct. It is working fine for me.

Edit: Found the solution here: https://www.b4x.com/android/forum/t...g-rapid-”-b4a-3-50-version.38981/#post-230988

B4X:
#Region  Project Attributes
    #ApplicationLabel: html test
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
    #DebuggerForceStandardAssets: true
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private WebView1 As WebView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Activity.LoadLayout("Main")
    WebView1.LoadURL("file:///android_asset/test.html")

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
 

Attachments

  • htmltest.zip
    7.8 KB · Views: 178
Upvote 0

casher2

Member
Licensed User
Longtime User

Brilliant! Thank you! Suspect my problem was with: #DebuggerForceStandardAssets: true
RE My comment...writing unique app for medical staff and was facing 'high anxiety'. Thanks again!!
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…