我正在尝试在 android 上启动已配置的电子邮件客户端以发送附件。问题是,当我在模拟器中执行此操作时,没有配置电子邮件客户端来执行任何发送。我还配置了 onActivityResult() 以尝试阻止程序中的火车失事,但当事情爆发时它似乎无法控制。为什么?
这是我的 Intent :
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{""});
intent.putExtra(Intent.EXTRA_SUBJECT, CSV_MAIL_SUBJECT);
intent.putExtra(Intent.EXTRA_TEXT, CSV_MAIL_MSGBODY);
intent.putExtra(Intent.EXTRA_STREAM, createCSV.tempfile.toURI ());
try
{
startActivityForResult (intent, CSV_MAIL_RESULT_CODE);
}
catch (ActivityNotFoundException anf)
{
Log.d (TAG, "Activity not configured.");
//TODO: toast or something here..
}
最佳答案
Thing is, when I do it in the emulator, there is no email client configured to do any sending
这应该从您的 startActivityForResult()
调用中引发一个 ActivityNotFoundException
。
顺便说一句,你的 MIME 类型是错误的。它应该是 text/plain
。
I've also configured onActivityResult() to try and stop the train-wreck within the program but it doesn't seem to be getting control when things blow up. why?
因为,如果我是对的,startActivityForResult()
失败了,所以您永远不会被 onActivityResult()
调用。
关于android:检查 intent.ACTION_SEND 的配置操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8512420/