trevordevore / levure

Application development framework for LiveCode
MIT License
32 stars 14 forks source link

"launch" with a Levure assets file? #94

Closed jim1001 closed 6 years ago

jim1001 commented 6 years ago

Trevor,

Should it be possible to use the LiveCode launch command on a file in a Levure assets folder?

Whilst developing I've been using media files stored in Levure asset folders so I know they'll work in the IDE & on my Android tablet. Been working fine.

Just now though I want to open a PDF file stored in one of my Levure asset folders with an external reader using the "launch" command. This works fine in the IDE but not on the tablet (reader says can't open file).

If I use "launch" with a PDF not shipped with the Levure app the reader opens it no problem.

Is that what you'd expect?

ps: using Levure & Git every day - a brilliant combination!

trevordevore commented 6 years ago

Being in the assets folder shouldn’t affect whether or not you can open the file.

  1. Have you confirmed that the path to the PDF is correct by using “their is a file” on the path you are passing to launch?
  2. If the file exists then is there anything different about the path in the assets folder? For example, does it have a space in the path whereas the paths that work don’t?
jim1001 commented 6 years ago

Thanks for the suggestions Trevor.

Have you confirmed that the path to the PDF is correct by using “their is a file” on the path you are passing to launch?

Yes, have done that. The file(s) exists. You're right - a good practice.

If the file exists then is there anything different about the path in the assets folder? For example, does it have a space in the path whereas the paths that work don’t?

I can't see anything different. The path is /data/app/.../base.apk/assets_en/PDFs/test.pdf I'm using the form launch URL ("file:" & myPath) which has worked fine for URLs throughout my app. Though I think this is the first time I've tried the launch command in a Levure app.

Am stumped for now.

spencerlearning commented 6 years ago

Probably on Monday, I will be trying to implement an Android PDF viewer inside my Levure app using this technique described in the LiveCode forum. The PDFs are in my Levure assets folder.

I will also experiment with the launch command and report my results.

jim1001 commented 6 years ago

Thanks for the comment Brian. I had a go with that technique a while ago & managed to get it working. To allow you to set the PDF inside your app I used MaxV’s way of overwriting the default PDF with the one you want to see. For the app I’m currently working on however I think an external PDF reader would be more suitable.

I’ll have more of a play with the launch command & see if I can figure out the problem. Be interested to hear what you find...

jim1001 commented 6 years ago

I've tested similar code in a non-Levure app and get a similar outcome. For a text file I'm trying to launch, the native text file handler says "Cannot read file..." and for a PDF the native apps return "failed to open file" or "file cannot be opened". I'd copied both of these files over with the app using the Standalone Application Settings > Copy Files.

trevordevore commented 6 years ago

Can try copying the file to a temp folder and opening it from there?

jim1001 commented 6 years ago

Thanks - that was exactly the workaround I was going to try & it does work. However I'm still puzzled why I've seen no mention anywhere of not being able to launch a file directly from the place to which it's copied with the app. Maybe because it's a virtual location files in there can only be read by the LiveCode app & not by any external app...

ps: in future where possible I'll do an equivalent test in a non-Levure app first before posting an issue here.

trevordevore commented 6 years ago

Perhaps it has to do with sandboxing? I'm not familiar with Android apps so I can't say for sure.

For future reference, building a Levure app uses the "copy files" feature of the standalone builder (just behind the scenes) so there shouldn't be anything different about a Levure app vs a non-Levure app when you build.

jim1001 commented 6 years ago

Perhaps it has to do with sandboxing? I'm not familiar with Android apps so I can't say for sure.

Think you're right. For the record, in a non-Levure Android app, launching a file in specialFolderPath(“External Documents”) does work.

For future reference, building a Levure app uses the "copy files" feature of the standalone builder (just behind the scenes) so there shouldn't be anything different about a Levure app vs a non-Levure app when you build.

Good to know.

Thank you.

trevordevore commented 6 years ago

If I understand correctly, using specialFolderPath("external documents") should be necessary for Levure or non-Levure applications. Isn't the idea that you package up a file with your app, create a copy in specialFolderPath("external documents"), and then pass the path to the that version of the file to launch url?

jim1001 commented 6 years ago

For the Levure app I first did something like this to get it working:

put levureAssetsFolder() & tFilename into tSrc
put "/sdcard/" & tFilename into tDest # tDest = location outside sandbox
put URL ("binfile:" & tSrc) into URL ("binfile:" & tDest)
launch URL ("file:" & tDest)

For the non-Levure app I first did something like this to get it working:

put specialFolderPath("engine") & tFilename  into tSrc
put "/sdcard/" & tFilename into tDest # tDest = location outside sandbox
put URL ("binfile:" & tSrc) into URL ("binfile:" & tDest)
launch URL ("file:" & tDest)

Then I was made aware of the undocumented specialFolderPath("external documents"). So I did something this in my non-Levure app:

put specialFolderPath("External Documents") & tFilename into tLaunchPath
launch URL ("file:" & tLaunchPath)

Here there is no need to copy the file out of the sandbox since specialFolderPath("External Documents") is already outside it.

I didn’t think you could use specialFolderPath inside a Levure app or would ever need to, since you specify relative paths using something like levureAppFolder() & "/assets" ...

But that was before I found you couldn't use launch URL on a file in such a Levure assets folder.

trevordevore commented 6 years ago

How are you getting the document in the non-Levure application into the specialFolderPath("External Documents") folder? Don't you still have to copy the file there before you can launch it?

jim1001 commented 6 years ago

In Standalone Application Settings Copy Files tab I specified it to be copied with the app. On the Android tab I selected "Write External Storage" under "Application Permissions". Then you can refer to it as I mentioned above. So your app could refer to the same doc copied with the app as specialFolderPath("External Documents") & tFilename or specialFolderPath("engine") & tFilename However launch URL will only work if you use specialFolderPath("External Documents") & tFilename since specialFolderPath("engine") & tFilename is private to the app.