android:检查 intent.ACTION_SEND 的配置操作?

标签 android android-intent

我正在尝试在 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/

相关文章:

Android 等待浏览器 Intent 完成

java - 使用 Android 模式和匹配器类(正则表达式)

java - Proguard.cfg 丢失

android - Xamarin.Forms 项目中已添加 NuGet 包

android - 如何在android中停止这个线程?

java - 在android中通过http url调用intent

android - 错误 ACTION_INSERT android 2.3

android - 在Android Studio中,如何配置gradle在创建签名发布APK时自动替换AdMob的AdUnitId

java - 油煎面包 block 居中自定义 View 和消失问题

android - CheckBox .isChecked() 不访问代码