A recent post on SCN asked about opening a local PDF in Android using Agentry (). As it turns out, after some additional testing the Android HTML browsers don’t have the ability to directly view PDF files like the iOS HTML control.
However, if you have an appropriate PDF viewer installer on your Android device (like Adobe Reader or Polaris Office) then those applications will register an intent filter with the OS so that when an attempt is made to view a PDF file the OS will automatically hand off the request to the installed application. This works great as long as the application opening the file can determine and set the data type of the file being opened.
It was suggested that we could use the Agentry URL action step to cause the OS to invoke the intent using a file:///path/to/pdf/file.pdf command. From the responses it appears this works for some users but in my case it doesn’t work (at least for my current device – Samsung Galaxy S4). However, since that option didn’t work for me I had to look at another option. My solution was to create a helper application to open the PDFs that is able to detect and set the appropriate MIME type so that the OS can prompt or open the appropriate application to view the PDF (Polaris Office in my case).
I created an android application that I so originally named External Document Launcher. My application registers a custom scheme (extdoclaunch) that accepts a single parameter of the path to the file to open. I use the OpenURL action step and create a rule to build the command.
My app receives the URL and based on the file extension builds the appropriate intent with the file and data type before invoking the file. The Data property referened in the rule points to the External Data Property on the attached document.
Since the OS now knows the type of the file it appropriately opens or prompts the user on what application they want to use. Since I have to know the appropriate MIME type to set I have a set list of application types that are currently supported (PDF, XLS, XLSX, DOC, DOCX, PPT, PPTX, MP3, TXT, PNG, GIF, JPG, JPEG).
To use the application simply install the .apk on your device and create the openURL action step similar to the above rule. When you run the action selecting one of the supported documents you should be prompted or the document should automatically open. If the file extension is not one of the supported types a popup message will be displayed saying “Unsupported Document Type”.
To download the apk visit this link (no Google account is needed to download the file).
I’ll work on a follow-up post with more details of the andorid application internals if there is more interest.