Search code examples
androidintentfilteremail-attachments

Android: Intent for receiving email attachment


I still haven't quite got this "Intent" thing down when it comes to the details. What I'd like to do is to receive an intent when a certain email attachment is opened. The attachment will be a file that is actually an SQLite database with a structure specific to my app, and with a file extension that is also specific to my app.

What I've noticed in experimenting with this is that, when I send the file attachment from my PC (using Thunderbird), it is coded with a MIME type of "application/octet-stream". When I try to open this on my Android phone (using K-9 mail), it tells me that there is no app for "application/octet-stream".

So what do I do in my app to be recognized as a servicing app for this particular type of attachment, especially since I expect it's not a good idea to try to open anything with this MIME type.


Solution

  • So what do I do in my app to be recognized as a servicing app for this particular type of attachment, especially since I expect it's not a good idea to try to open anything with this MIME type.

    You don't.

    Inventing new documents as email attachments doesn't work well pretty much anywhere. Android is just a notch worse in this regard.

    You cannot realistically set up an ACTION_VIEW <intent-filter> by MIME type, because your MIME type is too general. You cannot set up an ACTION_VIEW <intent-filter> by file extension, because there is no file extension on email attachments as is processed by the AOSP email app, and perhaps other email clients as well.

    I encourage you to abandon email attachments as a delivery vector for your files, and find some other solution where you can have a customized MIME type (e.g., download the files from a Web server, with the emails containing a link to the files). Then, an ACTION_VIEW <intent-filter> by MIME type can work OK.