Page 1 of 1

Opening files on Android

Posted: Wed May 15, 2013 2:43 pm
by bertBUSIbr8
Hi,



I understand that the browsercontrol under Android doesn't support the viewing of PDFs, docs, etc as it does on iOS.

Is there another way to get around that? Can you open a native or 3rd party app and have it display the file?
The files would be included in the app.


Many thanks,


Bert

Re: Opening files on Android

Posted: Wed May 15, 2013 4:10 pm
by Klaus
Hi Bert,

you could try to launch the document:
...
put specialfolderpath("engine") & "/pdfs/my_doc.pdf") into tFile
launch url tFile
put the result into tResult
## Now check tResult:
## 1. if EMPTY, everything is fine
## 2. if -> "no association" then the device has not been set up to open/display PDF files
## 3. whatever but not empty, something went wrong :-)
...
Check "launch URL..." in the dictionary.


Best

Klaus

Re: Opening files on Android

Posted: Wed May 15, 2013 4:48 pm
by bertBUSIbr8
Hi Klaus,


Thanks for the reply, will give that a try.


Regards,



Bert

Re: Opening files on Android

Posted: Tue Nov 21, 2017 1:04 am
by jim1001
We may never know if Bert ever tried Klaus's code.

However I found myself trying something similar. I can get native Android apps to launch documents (e.g. PDF, text) outside the app on the target filesystem. However not for files copied over with the app. I check in my LiveCode app that the files exist, however the native apps return "failed to open this file" or "file cannot be opened". I’ve copied them over manually to check they will open with the apps on the Android device & they do.

Probably me doing something stupid but has anyone managed to successfully launch a PDF or text document copied over with the app on an Android device? Klaus, did you try your own code? :wink:

Re: Opening files on Android

Posted: Tue Nov 21, 2017 2:33 am
by FourthWorld
If you add a call to the sysError function where you're currently getting the error message, you'll get the ID of the error as returned by the OS.

Re: Opening files on Android

Posted: Tue Nov 21, 2017 5:26 pm
by jacque
What syntax are you using? Are you using the "launch" command?

Re: Opening files on Android

Posted: Tue Nov 21, 2017 10:42 pm
by jim1001
Thanks for replies.
What syntax are you using? Are you using the "launch" command?
Yes, as Klaus did:

Code: Select all

put specialfolderpath("engine") & "/pdfs/my_doc.pdf") into tFile
launch url tFile
An easy workaround is to copy the file(s) from the app specialfolderpath to an outside location and launch URL on that location. That works fine.

However I haven't seen any mention of success or failure of launching a file under the specialfolderpath on android so I'm curious about it.
If you add a call to the sysError function where you're currently getting the error message, you'll get the ID of the error as returned by the OS.
Will try that shortly. As I mentioned, the right app tries to open the file but fails giving "failed to open this file" or "file cannot be opened".

Re: Opening files on Android

Posted: Tue Nov 21, 2017 10:53 pm
by Klaus
Hi Jim,
jim1001 wrote:
Tue Nov 21, 2017 1:04 am
...
Klaus, did you try your own code? :wink:
...
no, sorry, I do not develop for mobile, well, I don't even own any mobile device like a cell phone, tablet or something.
Yep, that's me! :D

Best

Klaus

Re: Opening files on Android

Posted: Tue Nov 21, 2017 11:58 pm
by jacque
As I mentioned, the right app tries to open the file but fails giving "failed to open this file" or "file cannot be opened".
Sound like it has to do with Android sandboxing. Normally an app is only allowed to access its own private files. There's an "external storage" option in the Android pane in standalone settings, which will allow your app to write outside its sandbox. You might have to resort to that. Write the file to a public location where other apps can access it.

I haven't ever had to write to public folders so I'm not sure what the path would be but I think there are some references in the forum here.

Edit: I just noticed specialFolderPath("external documents"). Try that.

Re: Opening files on Android

Posted: Fri Nov 24, 2017 12:25 am
by jim1001
Klaus, Jacque - thanks for your replies.

Klaus: you should have said - I could have sent you my old phone. Then you would have no excuse. Although I expect it wouldn't be a welcome gift :wink:

Jacque: specialFolderPath("External Documents") worked. I think it should be in the dictionary entry for specialFolderPath along with at least a mention of Android sandboxing (sandboxing is mentioned for iOS so it's a little inconsistent). Now I've seen there is a pending bug report for it.

Best wishes,
Jim