Opening files on Android

The place to discuss anything and everything about running your LiveCode on Android

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
bertBUSIbr8
Posts: 38
Joined: Thu Jun 28, 2012 2:48 pm
Location: West-Cork, Ireland
Contact:

Opening files on Android

Post by bertBUSIbr8 » Wed May 15, 2013 2:43 pm

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

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Opening files on Android

Post by Klaus » Wed May 15, 2013 4:10 pm

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

bertBUSIbr8
Posts: 38
Joined: Thu Jun 28, 2012 2:48 pm
Location: West-Cork, Ireland
Contact:

Re: Opening files on Android

Post by bertBUSIbr8 » Wed May 15, 2013 4:48 pm

Hi Klaus,


Thanks for the reply, will give that a try.


Regards,



Bert

jim1001
Posts: 143
Joined: Fri Jan 29, 2016 6:25 pm

Re: Opening files on Android

Post by jim1001 » Tue Nov 21, 2017 1:04 am

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:

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9823
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Opening files on Android

Post by FourthWorld » Tue Nov 21, 2017 2:33 am

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7228
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Opening files on Android

Post by jacque » Tue Nov 21, 2017 5:26 pm

What syntax are you using? Are you using the "launch" command?
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

jim1001
Posts: 143
Joined: Fri Jan 29, 2016 6:25 pm

Re: Opening files on Android

Post by jim1001 » Tue Nov 21, 2017 10:42 pm

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".

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Opening files on Android

Post by Klaus » Tue Nov 21, 2017 10:53 pm

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

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7228
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Opening files on Android

Post by jacque » Tue Nov 21, 2017 11:58 pm

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

jim1001
Posts: 143
Joined: Fri Jan 29, 2016 6:25 pm

Re: Opening files on Android

Post by jim1001 » Fri Nov 24, 2017 12:25 am

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

Post Reply

Return to “Android Deployment”