Mail on Android - Attachment not ok

20 replies [Last post]
jpenne's picture
jpenne
User offline. Last seen 1 day 59 min ago. Offline
Joined: 18 Jan 2011

Hi,

with this sample of code, I can take a screenshot and add it as an attachment on iPad and iPhone. However with the same code on android,
the mail popup opens oke, but it failed to add the attachment.

1
2
3
4
5
6
local function sendEmailFromScreenShot()
 local pictureDir = system.DocumentsDirectory 
 display.save(localGroup,"test.png",pictureDir)
 native.showPopup("mail", {attachment = {baseDir=pictureDir,   
 filename="test.png" , type= "image"}})
end

Greetings,

Jürgen

ps: if you need more info, just let me now

Replies

Joshua Quick
User offline. Last seen 8 hours 40 min ago. Offline
Staff
Joined: 31 Jan 2011

Jürgen,

I have confirmed that this is an issue. Only files from the resource directory can be successfully sent. It does not work from the Documents or Temporary directory (oops!). I am currently working on a solution. I expect to have a fix for this sometime this week. Thank you for reporting this issue.

jpenne's picture
jpenne
User offline. Last seen 1 day 59 min ago. Offline
Joined: 18 Jan 2011

Joshua,

thank you for the quick feedback. It is a pleasure to use this framework and to be part of this community.

Big thx from Belgium,

Jürgen

ps: we'll send you guys some business apps we've been working on the last couple of months because we know you guys are eager the get the business apps more in the spotlight.

Joshua Quick
User offline. Last seen 8 hours 40 min ago. Offline
Staff
Joined: 31 Jan 2011

Jürgen,

This bug is now fixed. This fix will be made available in daily build #716.

jpenne's picture
jpenne
User offline. Last seen 1 day 59 min ago. Offline
Joined: 18 Jan 2011

Joshua,

I'm gonna test this tonight in our business app on the samsung android, and i'll provide some feedback.

regards,

Jürgen

Joshua Quick
User offline. Last seen 8 hours 40 min ago. Offline
Staff
Joined: 31 Jan 2011

The daily build containing this fix is now available. Sorry about the delay. We had some technical difficulties on our end.

jpenne's picture
jpenne
User offline. Last seen 1 day 59 min ago. Offline
Joined: 18 Jan 2011

Joshua,

works perfectly now on the Samsung.
Thank you very much.

Jürgen

MeApps's picture
MeApps
User offline. Last seen 15 hours 32 min ago. Offline
Joined: 4 Jun 2011

Josh,

jpg attachment is not working on android. I have the same code above. jpg instead of png...

Joshua Quick
User offline. Last seen 8 hours 40 min ago. Offline
Staff
Joined: 31 Jan 2011

MeApps,

Back in December, there was a bug on Android where it would fail to attach files from a directory other than the system.ResourceDirectory. That was fixed in the beginning of January. Please upgrade to the newest daily build and it should work. We've been able to send JPG files just fine on our side... along with PNGs and TXT files too.

MeApps's picture
MeApps
User offline. Last seen 15 hours 32 min ago. Offline
Joined: 4 Jun 2011

Hi Joshua,

Thanks for your respond. I figured what was wrong. See:

1
2
3
4
5
6
7
8
9
local options = {attachment = att}
native.showPopup("mail", options)
for w = 1, #att do
    local path = system.pathForFile(att[w].filename, system.DocumentsDirectory )
    if path ~= nil then
        os.remove (path)
        path = nil
    end
end

in iOS this works fine. I assume once native.showPopup is called with the attachment I can delete the files. However, on Android that do not work.

Can we have a listener for showPopup that let us know the user cancel or send the message that was popped up?

Thanks!

Joshua Quick
User offline. Last seen 8 hours 40 min ago. Offline
Staff
Joined: 31 Jan 2011

MeApps,

Right, the native.showPopup() function is non-blocking on both iOS and Android. That means you were deleting your files before they were getting sent by the mail popup window. I think you're just getting lucky on iOS and I'm surprised it worked at all considering that the IO calls such as io.remove() are blocking and would delete the files immediately. The file's bits are still on storage, not zeroed out, so the popup may already have the stream at that point and you were getting really lucky, but it's definitely not guaranteed.

Anyways, a Lua listener would be nice and I'll write that up as a feature request. But what you can do "today" is delete your files when your app exits or suspends. We do this internally in Corona for other things we temporarily cache.

MeApps's picture
MeApps
User offline. Last seen 15 hours 32 min ago. Offline
Joined: 4 Jun 2011

Understood! I like your workaround however, that would be a problem if the user gets a phone call (suspends), true? Maybe I can put it in the temporary directory? Does that get cleared out by the OS, if so when?

Thanks!

Joshua Quick
User offline. Last seen 8 hours 40 min ago. Offline
Staff
Joined: 31 Jan 2011

Regarding the Lua listener, after thinking about it further, its not that simple. Just because the e-mail popup's "Send" button was pressed does not mean the e-mail is sent immediately. It can take a long time to send due to a slow 3G or Edge connection... or it can be in the pending state because you do not have Internet access at all. Unfortunately, the mail client does not provide us events when the mail actually got sent (as far as I've seen). We only know when the mail popup is closed. So, this mean you need to hold on to the files and give the user the ability to manage the files themselves. For small temporary files, I suppose you just have to just hold on to them and re-use them the best you can.

Anyways, that's my 2 cents.

MeApps's picture
MeApps
User offline. Last seen 15 hours 32 min ago. Offline
Joined: 4 Jun 2011

Got it. I think your workaround would be fine when the application exits.

While we are on the subject of e-mail attachments, are there any plans for compressing image files into zips and/or pdfs? Right now multiple files are attached separately. It would be nice to have the ability to compress the image files into zip or insert them into a single pdf.

Thanks!

Joshua Quick
User offline. Last seen 8 hours 40 min ago. Offline
Staff
Joined: 31 Jan 2011

We currently do not support reading/writing to ZIP or PDF files. I agree that zip file support would be really nice and we've received many requests for that.

You might want to search the Internet for an open-source Lua library that supports zip files. It would have to be written in pure Lua to work (no binary dependencies), but if you can find something then that would solve this and not have to wait on us to implement it.

MeApps's picture
MeApps
User offline. Last seen 15 hours 32 min ago. Offline
Joined: 4 Jun 2011

Yes, so needed. Thats that thing, everything I have found for zips and pdfs has binary dependencies :-(

Joshua Quick
User offline. Last seen 8 hours 40 min ago. Offline
Staff
Joined: 31 Jan 2011

Well, I'm sorry we've disappointed you here. We know this feature is important for business apps, which we want to focus more on this year. It sounds like you fall into this category, so hopefully what we release later down the road this year will interest you.

MeApps's picture
MeApps
User offline. Last seen 15 hours 32 min ago. Offline
Joined: 4 Jun 2011

Yes, our sports education apps are hybrid apps, a mixture of both. I am certain that you guys will to that. We are actually planning a trip to visit you guys and enlightened you guys about our apps and plans. We are steady in the top 50 in the app store in sports. So, these features and more are key to our success.

Thanks!

jpenne's picture
jpenne
User offline. Last seen 1 day 59 min ago. Offline
Joined: 18 Jan 2011

Joshua,

neat that you guys are focussing on business apps this year, it is very welcome. We did already a few business proof of concepts for clients and I must say they were impressed with what they saw, but making the corona api more business minded, is always neat.

But if you think out of the box, a lot of things can be done with the current API, and as in every project the exotic features can be pulled down the product backlog.

I will email some of the business POC's to ansca soon, when the POC are turned in to general ones.

Jürgen

MeApps's picture
MeApps
User offline. Last seen 15 hours 32 min ago. Offline
Joined: 4 Jun 2011

Joshua,

How can I get return a list of files from a directory?

Thanks!

Joshua Quick
User offline. Last seen 8 hours 40 min ago. Offline
Staff
Joined: 31 Jan 2011

Corona does not have an API for fetching all of the files within a directory. There's no way to do this at the moment, at least that I'm aware of.

Viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.