Loading Local Files with Browser Widget on Android
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Loading Local Files with Browser Widget on Android
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?
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
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
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
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.
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
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)
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
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
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
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)
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)
-
- Posts: 12
- Joined: Thu Feb 12, 2015 12:22 pm
Re: Loading Local Files with Browser Widget on Android
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
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
- Attachments
-
- Browsertest2.livecode.zip
- (1.24 KiB) Downloaded 296 times
Last edited by dbeugeling on Sun Mar 19, 2017 3:56 pm, edited 1 time in total.