Robot Head
Robot Head

Reputation: 446

Xamarin Forms (Android) - Associate app with custom file type

I wish to associate the file extension '.etd' with Android so that files with this extension will open the app when tapped.

I've been all over the internet and there are many combinations of code to implement, yet absolutely nothing works unless I use a generic file type such as '.txt'.

The 'Open with...' menu will appear with the following IntentFilter declaration in MainActivity.cs when I use a .txt file:

[IntentFilter(new[] { Intent.ActionView }, Categories = new[] { Intent.CategoryDefault }, DataMimeType = @"text/plain")]

However, the code below, and numerous permutations and variations, don't do anything (trying to open an .etd file gives an 'unable to open file' error):

[IntentFilter(new string[] { Intent.ActionView }, Categories = new string[] { Intent.CategoryDefault, Intent.CategoryBrowsable }, DataScheme = "file", DataHost = "*", DataMimeType = "*/*", DataPathPattern = ".*\\\\.etd")]

Also, nothing I can find explains what to do if I eventually do get the file association working either, i.e. how to access the file and work with it. Edit: I've worked this last bit out now (by renaming my files to .tsv and using 'text/tab-separated-values' as the DataMimeType), so now I just need to know how to associate .etd files with my app.

Upvotes: 0

Views: 788

Answers (1)

Wendy Zang - MSFT
Wendy Zang - MSFT

Reputation: 10938

The .etd file extension do not have the matching DataMimeType. So we could not associate the file extension '.etd' with Android.

There are too many types so that I could not upload all of them. For more details, please check the link. https://github.com/khellang/MimeTypes/blob/master/src/MimeTypes/MimeTypes.cs.pp

Here are the types for e part and t part for your reference.

static MimeTypes()
    {
        s_fallbackMimeType = DefaultFallbackMimeType;

        s_typeMap = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
        {
           
            { "ear", "application/java-archive" },
            { "ecma", "application/ecmascript" },
            { "edm", "application/vnd.novadigm.edm" },
            { "edx", "application/vnd.novadigm.edx" },
            { "efif", "application/vnd.picsel" },
            { "ei6", "application/vnd.pg.osasli" },
            { "elc", "application/octet-stream" },
            { "emf", "application/x-msmetafile" },
            { "eml", "message/rfc822" },
            { "emma", "application/emma+xml" },
            { "emz", "application/x-msmetafile" },
            { "eol", "audio/vnd.digital-winds" },
            { "eot", "application/vnd.ms-fontobject" },
            { "eps", "application/postscript" },
            { "epub", "application/epub+zip" },
            { "es", "application/ecmascript" },
            { "es3", "application/vnd.eszigno3+xml" },
            { "esa", "application/vnd.osgi.subsystem" },
            { "esf", "application/vnd.epson.esf" },
            { "et3", "application/vnd.eszigno3+xml" },
            { "etx", "text/x-setext" },
            { "eva", "application/x-eva" },
            { "evy", "application/x-envoy" },
            { "exe", "application/octet-stream" },
            { "exi", "application/exi" },
            { "exr", "image/aces" },
            { "ext", "application/vnd.novadigm.ext" },
            { "ez", "application/andrew-inset" },
            { "ez2", "application/vnd.ezpix-album" },
            { "ez3", "application/vnd.ezpix-package" },                              
            { "t", "text/troff" },
            { "t3", "application/x-t3vm-image" },
            { "t38", "image/t38" },
            { "taglet", "application/vnd.mynfc" },
            { "tao", "application/vnd.tao.intent-module-archive" },
            { "tap", "image/vnd.tencent.tap" },
            { "tar", "application/x-tar" },
            { "tcap", "application/vnd.3gpp2.tcap" },
            { "tcl", "application/x-tcl" },
            { "td", "application/urc-targetdesc+xml" },
            { "teacher", "application/vnd.smart.teacher" },
            { "tei", "application/tei+xml" },
            { "tex", "application/x-tex" },
            { "texi", "application/x-texinfo" },
            { "texinfo", "application/x-texinfo" },
            { "text", "text/plain" },
            { "tfi", "application/thraud+xml" },
            { "tfm", "application/x-tex-tfm" },
            { "tfx", "image/tiff-fx" },
            { "tga", "image/x-tga" },
            { "thmx", "application/vnd.ms-officetheme" },
            { "tif", "image/tiff" },
            { "tiff", "image/tiff" },
            { "tk", "application/x-tcl" },
            { "tmo", "application/vnd.tmobile-livetv" },
            { "toml", "application/toml" },
            { "torrent", "application/x-bittorrent" },
            { "tpl", "application/vnd.groove-tool-template" },
            { "tpt", "application/vnd.trid.tpt" },
            { "tr", "text/troff" },
            { "tra", "application/vnd.trueapp" },
            { "trm", "application/x-msterminal" },
            { "ts", "video/mp2t" },
            { "tsd", "application/timestamped-data" },
            { "tsv", "text/tab-separated-values" },
            { "ttc", "font/collection" },
            { "ttf", "font/ttf" },
            { "ttl", "text/turtle" },
            { "ttml", "application/ttml+xml" },
            { "twd", "application/vnd.simtech-mindmapper" },
            { "twds", "application/vnd.simtech-mindmapper" },
            { "txd", "application/vnd.genomatix.tuxedo" },
            { "txf", "application/vnd.mobius.txf" },
            { "txt", "text/plain" },
            
            
        };
    }

Upvotes: 1

Related Questions