How to send/open email attachments from android app?

15,993

Solution 1

I would like to somehow send a file from my app on one android device to my app on another device. This can be done any which way, and I'm open to suggestions if you can tell me how to send over network or something like that.

Write a Web service. Or use Amazon SQS.

be able to send my file (stored on sd card or somewhere on device) as an attachment

As is written up here, you could try:

Intent sendIntent = new Intent(Intent.ACTION_SEND);

sendIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
sendIntent.putExtra(Intent.EXTRA_STREAM, ...);
sendIntent.setType(...); 

where the first ellipsis is the path to your chosen file and the second ellipsis is a suitable MIME type.

and have my app recognized by android as the app to open an attachment with the file extention (.lst)

Never rely on file extensions. Use MIME types. You can set up an activity with an intent filter that offers ACTION_VIEW support for your MIME type.

Solution 2

I did this in order to process vcf files attached to mails and it worked. Here is the intent filer:

        <intent-filter>
            <category android:name="android.intent.category.DEFAULT" />
            <action android:name="android.intent.action.VIEW" />
            <data android:mimeType="text/x-vcard" />
        </intent-filter>

See the whole code in http://code.google.com/p/card-catcher.

Share:
15,993
CodeFusionMobile
Author by

CodeFusionMobile

I am an electrical engineering/computer scientist. I did my undergrad at South Dakota State University and am currently pursuing a Masters in Robotics at University of Pennsylvania. I have worked as a software developer at Daktronics, Inc, a scoreboard and stats company. I also am an independant Android developer.

Updated on June 04, 2022

Comments

  • CodeFusionMobile
    CodeFusionMobile almost 2 years

    I would like to somehow send a file from my app on one android device to my app on another device. This can be done any which way, and I'm open to suggestions if you can tell me how to send over network or something like that.

    Currently, I'm looking at sending the file as an email attachment, but I haven't found any good documentation on how to do it. I need two things to accomplish this, be able to send my file (stored on sd card or somewhere on device) as an attachment, and have my app recognized by android as the app to open an attachment with the file extention (.lst).

    Any thoughts?

    The files will all be fairly small xml text files if that makes a difference.

  • CodeFusionMobile
    CodeFusionMobile over 14 years
    I got the send part working just fine but I can't seem to get the email app to let me open the file. I specified the MIME type and added an intent filter, but there is still no preview or download button in the email app. What am I missing/how should I do that part?
  • CommonsWare
    CommonsWare over 14 years
    I recommend you open up a fresh question, and paste in your manifest (or at least the <activity> element in question), so we can see your intent filter.
  • finiteloop
    finiteloop almost 13 years
    I tried doing this, however it opened an MMS, with as far as I can tell, lacked the attached file. Note this was tried on the emulator.