Reputation: 3058
I would think this is pretty basic but apparently its not. My app is downloading office documents such as XLS, PDFs, Docs, etc - they are downloading just fine and the user can navigate on their phone (using File Manager) to their downloads directory and see and open the file from there.
After the download is complete I want the user to be able to open that file from within my app - it would then launch an app picker or auto-launch the phones default viewer for that file type.
For the life of me I can't figure out how to do it on Android and iOS. I would think there was some universal plugin, but the only plugins I can find are cordova-plugin-opener
and cordova-plugin-opener2
and both of those are 10yrs and 5yrs old and aren't maintained - AND they are for Android only. Even if I use one of them for Android (and it still works), how would do you do it on iOS?
Does anyone have a solution you can point me to that would satisfy opening files on both Android and iOS? Preferably some simple native solution like window.open();
I must have done 50 different types of google searches and yet I have found no concise answer.
Upvotes: 1
Views: 666
Reputation: 3058
Well, for anyone interested https://github.com/pwlin/cordova-plugin-file-opener2
still works even though its stated it is no longer maintained.
I tested successfully Android API 33. I have yet to test on iOS...will update later when I get to it.
The one caveat for Android is you MUST pass a correct MIME type (IE: application/pdf
) for the file you are trying to open. A nice enhancement would be if someone added all the current MIME Types to the plugin so it would automatically select the correct one. Other than, it still worked.
Upvotes: 3