Page 1 of 1
Loading Local Files with Browser Widget on Android
Posted: Thu May 12, 2016 8:32 am
by n.allan
I just updated my app to use the browser widget instead of mobileControlCreate "browser". I am no unable to load links to local files.
The files are copied in the standalone application settings and they were accessible by using the link with the old browser.
"file:" & specialFolderPath("engine") & "/info.html"
The browser widget is working because I can load Internet links no problem.
I have tried
set the URL of widget "Browser" to "file:" & specialFolderPath("engine") & "/info.html"
set the URL of widget "Browser" to "file:" & specialFolderPath("documents") & "/info.html"
The browser widget just says "ERR_FILE_NOT_FOUND"
It works in the IDE but not on Android. What am I missing here?
Re: Loading Local Files with Browser Widget on Android
Posted: Thu May 12, 2016 10:11 am
by Klaus
Hi n.allan,
shouldn't this be:
...
set the URL of widget "Browser" to ("file://" & specialFolderPath("resources") & "/info.html")
...
Some general hints:
1. Always use brackets when concantenating strings for object and or pathnames!
May work here and there, but will fail when you least exspect it!
2. Local files need 2 extra slashes in the URL, see above!
3. Files copied to your standalone via the "Copy files" tab in the standalone builder settings will be found in -> specialfolderpath("resources")
Which is the same as the engine folder on mobile, but for crossplatform reasons stick to RESOURCES.
Hope that helps.
Best
Klaus
Re: Loading Local Files with Browser Widget on Android
Posted: Thu May 12, 2016 1:57 pm
by n.allan
Still no dice.
I also tried removing 1 slash to see if the path is being fussy.
set the url of widget "Browser" to ("file:/" & specialFolderPath("resources") & "/info.html")
still ERR_FILE_NOT_FOUND
The file is definitely there in the apk bundle.
I'm a bit bummed I deleted my old code as it worked fine with mobileControlCreate(), I just fancied using the browser widget. Never mind backwards we go again.
Re: Loading Local Files with Browser Widget on Android
Posted: Thu May 12, 2016 2:52 pm
by n.allan
Yup all works OK with the old browser control on both my devices. 1 slash or 2 slashes. I might even file bug report. It might be a bug on the specialFolderPath() function itself. I did try displaying the url in a message box before setting the browser url but there is no difference between what I am using with the old browser and the new widget. (I wouldn't even know what the correct path format for Android was anyway)
I also notice on windows that...
specialFolderPath("engine") returns the path with back slashes whilst specialFolderPath("documents") returns forward slashes. I know these can be platform dependent but it might be better to standardise this as windows understands both (in LiveCode anyway)
Re: Loading Local Files with Browser Widget on Android
Posted: Thu May 12, 2016 3:15 pm
by Klaus
Hi n.allen,
hm, then I consider this a bug, same for backward slashes in specialfolderpath("engine")!
Internally LC ALWAYS uses the UNIX forward SLASH as a pathdelimiter on whatever platform!
Please consider to report this as a bug here:
http://quality.runrev.com
Thanks!
Best
Klaus
Re: Loading Local Files with Browser Widget on Android
Posted: Thu May 12, 2016 5:00 pm
by n.allan
Re: Loading Local Files with Browser Widget on Android
Posted: Tue Sep 06, 2016 1:29 am
by KimD
With regard to the original post - I've managed to get local html files working in the browser widget (on Windows IDE, Android simulator, and real Android device), but I had to use slightly different code depending on the environment.
Switch the environment
Case "mobile"
set the URL of widget "Browser" to empty
set the htmltext of widget "Browser" to URL("file:" & specialFolderPath("engine") & "/TestLinks.html")
Break
Case "development"
set the URL of widget "Browser" to "file:" & specialFolderPath("engine") & "/TestLinks.html"
Break
end Switch
Kim (on LC8.0.2)
Re: Loading Local Files with Browser Widget on Android
Posted: Wed Mar 15, 2017 10:21 pm
by dbeugeling
Thank you Kim,
unfortunately, I could not get it to work, but I found out, that you need some more //.
See my upload. (You pick your own user path and picture, please).
Dick