I am trying to add emailing capabilities to my Android application. What I am trying to do actually is send a file that contains a json string representing some application data by using the ACTION_SEND intent. The problem is that on my device, an HTC Desire with Froyo, Gmail sends the actual email, but not the attachment, even though I see the attachment when the Gmail app starts as attached. However, on the emulator, using the default email application, this works just fine. This also works if I am using an application such as ASTRO file manager to send the attachment directly from the SD card with it's default suggested mime type. Anyone encountered something similar? My code looks something like this:
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("application/sal");
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "shopping list");
Log.d(TAG, "attachment file: " + Uri.parse("file:/" + fileWithPath));
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:/" + fileWithPath));
I have tried a variety of mime types also, such as application/json or text/plain with same result. 开发者_StackOverflow中文版
Apparently, there is some issue with the URI's starting with file:// on Gmail for Android, so I found some recommendations regarding how to handle attachments and files which said that a content provider internal for the application, to access the file content should be used. Examples for implementing something like that can be found in OI FileManager here and here. I have looked over the source code a fore mentioned and tried implementing my own content provider to access the file I want to attach, and it worked. I hope this information is helpful for others that may try this.
精彩评论