Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Register new mime type in android

this is related to question how to open an attachment with my applicacion from within the email app? (mime type, intent filter ...) which I thought I had it solved, but it is not.

I found that some email clients (Samsung Galaxy SII built in email client, for instance) doesn't honor the sendIntent.setType() method and when adding an attachment to an email it is not adding the mime-type specified in the setType method. The consequence is that I cannot open the attachment when the email arrives.

So in order to be able to open an attachment from any email client I think they only way I have is to create a new mime type that is associated to my custom extension.

But I cannot find any way to register a new mime type. I know it can be done as some apps do it (ASTRO File Explorer), but I don't know where else to look for information on adding a new mime type.

EDIT (2012,Oct, 1st) ASTRO File Explorer adds only mime types for its process. They cannot be read outside its process, so I don't have any example where it works.

I have been looking at the MimeTypeMap source code and looks like it only uses a predefined set of mime types and you cannot add a new one.

I tried using reflection (just to check) and was able to add a mime type, BUT it is only visible to my process, as if my process had its own copy of the MimeTypeMap, so the email client will still not open the attachment.

someone can help?

thanks in advance

like image 215
richardtz Avatar asked Sep 21 '12 09:09

richardtz


People also ask

Can MIME type be changed?

If your files do not match the predefined MIME types, you can edit the MIME types to add filename extensions and magic headers. You cannot add new MIME types, however.


1 Answers

It's my understanding that your data specification is base solely on the file extension .xyz. So when you declare it in your intent filter, you need to make sure that you're being as generic as possible towards all parameters except the patternPath.

Try splitting it up into several <data> tags and make sure it's agnostic towards the mimeType:

    <data android:scheme="file" />                               
    <data android:mimeType="*/*" />
    <data android:pathPattern=".*\\.xyz" />
    <data android:host="*" />

See also the documentation on <data> to make sure all subtypes match.

It's my understanding that the underlying data structure of your file might cause problems on some devices. Suppose for instance that your .xyz file type is XML; the e-mail client may think that providing the text/xml mime type is more specific than the one you declared, and invoke it instead.

In such cases, a solution might instead be to declare multiple intent filters, once also including <data android:mimeType="text/xml" />. (This is more or less in line with what this answer suggests.)

like image 148
Paul Lammertsma Avatar answered Oct 21 '22 19:10

Paul Lammertsma