Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open KML/GPX files in appropriate external map app

My Flutter (Android and iOS) app generates KML or GPX files, which works as expected.

Now I want to add a button "Open file" which should open such a system dialog where the installed map or other consuming apps (which can handle such formats) are listed to be chosen.

How can I open this dialog? How can I find the format-related apps and how can I send the file to these apps. I guess, there is a plugin for this, but couldn't find one. It must work on Android and iOS, nice-to have is web support.

I just saw open_file but I am not quite sure, if it works as expected because it doesn't list support for KML/GPX.

Thanks in advance!

like image 556
S-Man Avatar asked Nov 06 '22 04:11

S-Man


1 Answers

If you found a Flutter plug-in that is open source like open_file, you could just add in the MIME types yourself.

For KML format: https://en.wikipedia.org/wiki/Keyhole_Markup_Language

For GPX format: https://en.wikipedia.org/wiki/GPS_Exchange_Format

As the package is open source I was thinking of modifying the code, as the mapping appears to be straight forward:

https://github.com/crazecoder/open_file/blob/master/ios/Classes/OpenFilePlugin.m

and

https://github.com/crazecoder/open_file/blob/master/android/src/main/java/com/crazecoder/openfile/OpenFilePlugin.java

You would need to fork the projects and add in the types you wanted.

Alternately you've posted issue ticket #116

where the repo owner responded with

OpenFile.open("/sdcard/example.txt", type: "text/plain", uti: "public.plain-text");

Do respond if that works, as I was uncertain if both of the different platforms' filetype (uti vs MIME type) works universally in Flutter or if you have platform specific detection code to assign the filetype correctly.

like image 192
Morrison Chang Avatar answered Nov 15 '22 05:11

Morrison Chang