[File Viewer Plugin] [File Viewer Plugin] Version 1.0.3 (OS11) Doesnt work with Android

Forge Component
(6)
Published on 1 Apr by Experts
6 votes
Published on 1 Apr by Experts

I am developing a News/Alerts area in my application to allow the business to get updates on Health and Safety / COVID 19 directly into our users hands. 


The News items will have document attachments. I am using File Plugin 2.0.0 and File Viewer Plugin 1.0.3 to achieve this.

The News items are saved locally on the device, however the attachments are not (only required to view if users have network access). 

To view the File, I have an Action retrieve the File Binary from the server, Then using File Plugin it saves the File to a directory, then File Plugin Viewer will open that. 


It works perfectly on iOS (with or without isToPreview)

However on Android it will not work. From debugging I have found that both the File Plugin and File Viewer Plugins do not return any errors where I have checked.

I have re generated the apps (logged out, uninstalled the app and re installed) 

I have tried the following:

For the filepath: Replace(SaveFile.Uri, "file://", "content://")

I then tried changing the File plugin save StorageTypeId to External, which seemed to partly work. On some Android devices looks as though its bringing up the page to save/open the file but it only appears briefly and then goes back to the app. 

Any one else having similar issues?

Chris

Benjith Sam wrote:

Hi Christopher Kennedy,

Refer this Forum Post: https://www.outsystems.com/forums/discussion/59609/opening-doc-in-fileviewer/?utm_source=community&utm_medium=email&utm_campaign=forum-reply=#Post229359


Hope this helps you!


Regards,

Benjith Sam


Hello Benjith, 


I checked that out and tried to emulate what they attempted, including removing the "Create Directory" Step.

however it doesnt seem to want to work for me. I have tried this using both internal and external storage types but same issue. 

It looks like the file is about to open, as it opens google drive preview screen, but only for a moment then it just jumps back to the App. 

Hi Christopher,

Can you share how you are setting the properties in the SaveFile and OpenDocument actions?

Or attach the oml?

What kind of documment you are attaching?


Regards,

Leandro.

Leandro Correa wrote:

Hi Christopher,

Can you share how you are setting the properties in the SaveFile and OpenDocument actions?

Or attach the oml?

What kind of documment you are attaching?


Regards,

Leandro.

I intend on allowing users to upload any type of document, as this functionality works for iOS.

Unfortunately cant provide the oml as there are a lot of dependencies etc:


What I have in my "openFile" action:

Firstly it checks for network access as it will need access to the server to get the content for the file. 

The "GetAttachmentContentandOS Action takes the EvidenceAttachment.ID and returns the content that goes with it. I have test this and know that data is being returned. In this action it also returns what OS is being used which I use to set a variable "isIOS"



It will then check the file plugin is available which has been tested and works. The File Plugin's Action "SaveFile" is set up as you can see. The Binary Data is the data retrieved from the server in the previous server action. The filename is also correct as it is also displayed on the screen where the News articles can be read and again working correctly on iOS.

It then checks that the DocumentViewerPlugin is available, which again has been tested on both Android and iOS. The hidden paths go to an array of Messages that have been useful to finding out what stage, if any, it is failing.


Then Finally. You can ignore the isLoadingFile assign as this controls a popup loading screen. 

The OpenDocument Action is called, with the details there. And below are the mimeTypes of the files which are collected when the file is uploaded initially. The middle one is a Word document, but even this is able to be loaded on iOS.

Here is what the screen looks like if that helps:

The "OpenFile" Action detailed is called when the link/filename is tapped.


Thanks

Chris


Leandro Correa

Does it look like something is incorrect there?

I have got the Android app to print the SaveFile.Uri in a Message. 

Wonder if that helps at all.

I have tried replacing the "file:///" with "content:///" but that doesnt work. 

Christopher Kennedy wrote:

Leandro Correa

Does it look like something is incorrect there?

No, the logic looks great :( 


Christopher Kennedy wrote:

I have got the Android app to print the SaveFile.Uri in a Message. 

Wonder if that helps at all.

I have tried replacing the "file:///" with "content:///" but that doesnt work. 

I'm not sure about the three "///" is ok. 

Did you try with 2 "//"? 

As you did describe in the first post: Replace(SaveFile.Uri, "file://", "content://").


Thanks for the suggestion, 

I tried that then also tried:

Replace(SaveFile.Uri, "file://", "content://")

Replace(SaveFile.Uri, "file:///", "content://")

Replace(SaveFile.Uri, "file:///", "content:///")

Replace(SaveFile.Uri, "file:///", "file://")

Changed the SaveFile storagetype from external to internal or each one, still doesnt open. 

Even tried using Javascript to set FilePath variable with $parameter.FilePath = "Documents" which still results in the file not opening

I need a way of getting it to save to "content://......." But since other users have this working recently, I thought I could too. 

The closest I have come to it working (on a pixel 3 which im testing on) is it opens the Google Drive preview, but then autocloses again.

This is when $parameters.FilePath = "Documents" and then The open document just uses SaveFile.Uri (no replacement), the filename is correct but maybe the binary is not being saved correctly on Android? The "OpenDocument" Action returns success when it is called? 


any other suggestions?


Try this another forge component to preview pdf file and so to test if the document is saving correctly.

https://www.outsystems.com/forge/component-overview/6223/mobile-pdf-preview

Thanks for the suggestions.

Looked at mobile pdf viewer but there was no stable version for my environment, im on OS11, so not sure why. 

I did however get the data from the SaveFile.Uri, and then output the binary size as a message on the screen, which is the same size as the content which is saved. 

So this makes me think that the Content is being saved correctly, just OpenDocument cant open it correctly on Android.


Dont know what Im doing wrong. Seems this just doesnt work for Android. 

Ive tried re generating the apps and uninstalling and reinstalling on the Device. 

Also not sure it makes a difference but the app was generated using MABS 6.1

Solution

Ive Fixed it!

After creating a very simple test app where it was loading a file from the resources I was able to make it work.

Turns out the Android version cant handle spaces in the filename. 

So I was passing "HSEQ 0120 Document.pdf" and it wasnt working,
but when I passed "HSEQ0120Document.pdf" it does work.

Thank you everyone who gave me suggestions and Leandro Correa for checking my work. 


Solution

Christopher Kennedy wrote:

Ive Fixed it!

After creating a very simple test app where it was loading a file from the resources I was able to make it work.

Turns out the Android version cant handle spaces in the filename. 

So I was passing "HSEQ 0120 Document.pdf" and it wasnt working,
but when I passed "HSEQ0120Document.pdf" it does work.

Thank you everyone who gave me suggestions and Leandro Correa for checking my work. 



Good to know that.

Below is the only learning right.

Turns out the Android version cant handle spaces in the filename. 

So I was passing "HSEQ 0120 Document.pdf" and it wasnt working,
but when I passed "HSEQ0120Document.pdf" it does work.

Great news Christopher!

#kudos



There is a new forge component that implements the filename sanitisation that was reported here (android filenames can't have spaces):

https://www.outsystems.com/forge/component-overview/8322/fileviewerdemo

This component makes usage of FilePlugin, FileTransferPlugin and FileViewerPlugin.

Is a good sample about how to handle files on mobile devices.


Hope it helps,

Best regards