如何等待电子邮件的意图来完成,并得到结果? [英] How to wait for email intent to finish and get result?

查看:193
本文介绍了如何等待电子邮件的意图来完成,并得到结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Andr​​oid应用程序,我可以以编程方式打开默认的电子邮件编辑器,主题,并使用信息如下:

In my Android app, I am able to programmatically open up the default email editor with To, Subject, and Message using the following:

Intent emailIntent=new Intent(Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_EMAIL, toemail);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(Intent.EXTRA_TEXT, body);
emailIntent.setType("text/plain");
emailIntent.setClassName("com.android.email", "com.android.email.activity.MessageCompose");
startActivity(emailIntent);

这个伟大的工程,但我需要直到用户完成与电子邮件的屏幕等待我的应用程序,也知道该邮件是否被发送或丢弃。

This works great, but I need to wait in my app until the user finishes with the email screen and also know whether the email was sent or discarded.

任何人都知道如何做到这一点?

Anyone know how to do this?

推荐答案

一般情况下,人们可以使用startActivityForResult(),它启动第二活动作为子活动。然而,在电子邮件活动的情况下,这不会出现工作的内部实现的可能是因为,。尝试张贴问题之前搜索:

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:

<一个href="http://stackoverflow.com/questions/3778048/how-can-we-use-startactivityforresult-for-email-intent">how我们可以用startActivityforResult()的电子邮件意图是什么?

实际的电子邮件的发送是异步的设计,所以该活动的电子邮件之前可能会返回实际被发送。我没有测试过这种情况特别,但是从上面的链接似乎活动返回一旦用户点击发送按钮。如果这足以满足你的使用情况,然后超,如果你需要知道,如果电子邮件实际发送你可能会对SOL。

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.

这篇关于如何等待电子邮件的意图来完成,并得到结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆