【问题标题】:gmail android app crashes when sending an intent with SEND TO使用 SEND TO 发送意图时,gmail android 应用程序崩溃
【发布时间】:2014-02-06 09:41:40
【问题描述】:

我正在从我的应用程序发送电子邮件意图以通过电子邮件客户端发送邮件。

Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", to[0], null));
                emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
                emailIntent.putExtra(Intent.EXTRA_TEXT, body);
                emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, attachments);

我的附件 uri 内容://com.test/logs/test.log

我的意图选择器显示了本机 android 电子邮件客户端和 gmail 客户端。

我已经在这里问了我的问题但没有回复:(

http://productforums.google.com/forum/#!mydiscussions/gmail/3ivhRlbmXc8

Error while sending email with attachment in gmail android app

电子邮件客户端工作正常,但是当我选择 gmail 客户端时它崩溃了。下面是堆栈跟踪。收件人地址实际上是空的

01-16 18:35:37.670: E/AndroidRuntime(6147): FATAL EXCEPTION: main
01-16 18:35:37.670: E/AndroidRuntime(6147): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.google.android.gm/com.google.android.gm.ComposeActivityGmail}: java.lang.NullPointerException
01-16 18:35:37.670: E/AndroidRuntime(6147):         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
01-16 18:35:37.670: E/AndroidRuntime(6147):         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
01-16 18:35:37.670: E/AndroidRuntime(6147):         at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-16 18:35:37.670: E/AndroidRuntime(6147):         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
01-16 18:35:37.670: E/AndroidRuntime(6147):         at android.os.Handler.dispatchMessage(Handler.java:99)
01-16 18:35:37.670: E/AndroidRuntime(6147):         at android.os.Looper.loop(Looper.java:137)
01-16 18:35:37.670: E/AndroidRuntime(6147):         at android.app.ActivityThread.main(ActivityThread.java:5103)
01-16 18:35:37.670: E/AndroidRuntime(6147):         at java.lang.reflect.Method.invokeNative(Native Method)
01-16 18:35:37.670: E/AndroidRuntime(6147):         at java.lang.reflect.Method.invoke(Method.java:525)
01-16 18:35:37.670: E/AndroidRuntime(6147):         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
01-16 18:35:37.670: E/AndroidRuntime(6147):         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-16 18:35:37.670: E/AndroidRuntime(6147):         at dalvik.system.NativeStart.main(Native Method)
01-16 18:35:37.670: E/AndroidRuntime(6147): Caused by: java.lang.NullPointerException
01-16 18:35:37.670: E/AndroidRuntime(6147):         at android.content.ContentResolver.acquireExistingProvider(ContentResolver.java:1116)
01-16 18:35:37.670: E/AndroidRuntime(6147):         at android.content.ContentResolver.getType(ContentResolver.java:257)
01-16 18:35:37.670: E/AndroidRuntime(6147):         at com.android.mail.compose.AttachmentsView.m(SourceFile:217)
01-16 18:35:37.670: E/AndroidRuntime(6147):         at com.android.mail.compose.ComposeActivity.a(SourceFile:672)
01-16 18:35:37.670: E/AndroidRuntime(6147):         at com.android.mail.compose.ComposeActivity.zW(SourceFile:583)
01-16 18:35:37.670: E/AndroidRuntime(6147):         at com.android.mail.compose.ComposeActivity.onCreate(SourceFile:445)
01-16 18:35:37.670: E/AndroidRuntime(6147):         at com.google.android.gm.ComposeActivityGmail.onCreate(SourceFile:54)
01-16 18:35:37.670: E/AndroidRuntime(6147):         at android.app.Activity.performCreate(Activity.java:5133)
01-16 18:35:37.670: E/AndroidRuntime(6147):         at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
01-16 18:35:37.670: E/AndroidRuntime(6147):         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
01-16 18:35:37.670: E/AndroidRuntime(6147):         ... 11 more

感谢和问候, 索拉夫

【问题讨论】:

  • 你的attachments 对象是什么,你是如何生成它的?
  • 感谢 cmets。你是对的,我删除了附件,它工作正常。通过附件,我发送了一些日志/文本文件“uris”

标签: android gmail


【解决方案1】:

我最近发现了 ICS MR1+ 的解决方案,同时试图找到一种方法将我的 ACTION_SEND_MULTIPLE 过滤到仅电子邮件应用程序。首先,像这样构建你的意图:

sendEmailIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
sendEmailIntent.setType("message/rfc822");
sendEmailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { "some@email.com" });                
sendEmailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
sendEmailIntent.putExtra(Intent.EXTRA_TEXT, "Body");
final ArrayList<Uri> uris = /* ... Your code to build the attachments. */
sendEmailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);

然后,如果您需要将其限制为电子邮件应用程序,请像这样限制它:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
    sendEmailIntent.setType(null); // If we're using a selector, then clear the type to null. I don't know why this is needed, but it doesn't work without it.
    final Intent restrictIntent = new Intent(Intent.ACTION_SENDTO);
    Uri data = Uri.parse("mailto:?to=some@email.com");
    restrictIntent.setData(data);
    sendEmailIntent.setSelector(restrictIntent);
}

这将使您能够通过 Gmail 发送而不会崩溃。您可能希望在 API 检查中执行 startActivity() 并尝试/捕获,然后删除选择器并在未找到任何活动时重试。

【讨论】:

  • 不知道...我在一个应用程序中使用它,它似乎可以在 Nexus 5 上运行。
【解决方案2】:

设置你的类型!

Intent emailIntent = new Intent(Intent.ACTION_SEND);
      emailIntent.setData(Uri.parse("mailto:"));
      emailIntent.setType("text/plain");


      emailIntent.putExtra(Intent.EXTRA_EMAIL, TO);
      emailIntent.putExtra(Intent.EXTRA_CC, CC);
      emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Your subject");
      emailIntent.putExtra(Intent.EXTRA_TEXT, "Email message goes here");

【讨论】:

  • 这对 Derek 没有帮助。请看看我上面的评论。问题似乎是附件
  • @saurav 否决票旨在确定有害的答案,而不是不能直接解决您的特定问题的答案。欢迎来到 SO。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多