How to wait for email intent to finish and get result? [duplicate]

本小妞迷上赌 提交于 2019-12-01 03:49:02
jfelectron

Normally, one could use startActivityForResult() which starts the second activity as a sub-activity. However, in the case of the email activity this doesn't appear to work, likely because of the internal implementation. Try searching before posting questions:

how can we use startActivityforResult() for Email intent?

The actual sending of an email is asynchronous by design, so the activity will likely return before the email is actually sent. I haven't tested this case specifically, but from the above link it seems that the activity returns once the user hits the send button. If this suffices for your use case then super, if you need to know if the email was actually sent you might be SOL.

This is going to be tricky. There is no standardized return value for email sending, and depending on the user's settings, the mail could be sent with the Email app, the Gmail app, or one of the many 3rd party email apps. They most likely all differ in how they handle ending the emails.

As for your question in general, you can use startActivityForResult() to start an activity and then continue after it finishes, with a return value indicating how things went. However, I'm pretty sure that most email apps won't give you a proper result here.

I'm tempted to say that you may need to handle the sending of the email yourself, i.e. write a simple function that connects to the SMTP and sends the mail out. I'm sure there are lots of libraries out there that handle all the heavy-lifting.

(You can, of course, experiment with startActivityForResult first - MAYBE the most common email apps do give you a return value.)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!