在 gmail android 应用程序中发送带附件的电子邮件时出错
Posted
技术标签:
【中文标题】在 gmail android 应用程序中发送带附件的电子邮件时出错【英文标题】:Error while sending email with attachment in gmail android app 【发布时间】:2014-01-26 04:46:42 【问题描述】:我一直在尝试发送带有附件的电子邮件。 也只寻找电子邮件客户回复。
我已关注此链接Send Email Intent。
下面是我的代码
Intent intent = new Intent(Intent.ACTION_SENDTO);
// Set MIME type to email message to avoid other non-email applications showing up
intent.setData(Uri.parse("mailto:"));
intent.putExtra(Intent.EXTRA_EMAIL, to);
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_TEXT, body);
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, attachments);
这样做,我在选择器对话框中获得了 gmail 和 android 电子邮件客户端。 当我点击 gmail 客户端时,出现以下错误。同样适用于 android 电子邮件客户端。
01-08 13:04:50.385: E/AndroidRuntime(13369): java.lang.RuntimeException: Unable to start activity ComponentInfocom.google.android.gm/com.google.android.gm.ComposeActivityGmail: java.lang.NullPointerException
01-08 13:04:50.385: E/AndroidRuntime(13369): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
01-08 13:04:50.385: E/AndroidRuntime(13369): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
01-08 13:04:50.385: E/AndroidRuntime(13369): at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-08 13:04:50.385: E/AndroidRuntime(13369): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
01-08 13:04:50.385: E/AndroidRuntime(13369): at android.os.Handler.dispatchMessage(Handler.java:99)
01-08 13:04:50.385: E/AndroidRuntime(13369): at android.os.Looper.loop(Looper.java:137)
01-08 13:04:50.385: E/AndroidRuntime(13369): at android.app.ActivityThread.main(ActivityThread.java:5103)
01-08 13:04:50.385: E/AndroidRuntime(13369): at java.lang.reflect.Method.invokeNative(Native Method)
01-08 13:04:50.385: E/AndroidRuntime(13369): at java.lang.reflect.Method.invoke(Method.java:525)
01-08 13:04:50.385: E/AndroidRuntime(13369): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
01-08 13:04:50.385: E/AndroidRuntime(13369): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-08 13:04:50.385: E/AndroidRuntime(13369): at dalvik.system.NativeStart.main(Native Method)
01-08 13:04:50.385: E/AndroidRuntime(13369): Caused by: java.lang.NullPointerException
01-08 13:04:50.385: E/AndroidRuntime(13369): at android.content.ContentResolver.acquireExistingProvider(ContentResolver.java:1116)
01-08 13:04:50.385: E/AndroidRuntime(13369): at android.content.ContentResolver.getType(ContentResolver.java:257)
01-08 13:04:50.385: E/AndroidRuntime(13369): at com.android.mail.compose.AttachmentsView.m(SourceFile:217)
01-08 13:04:50.385: E/AndroidRuntime(13369): at com.android.mail.compose.ComposeActivity.a(SourceFile:664)
01-08 13:04:50.385: E/AndroidRuntime(13369): at com.android.mail.compose.ComposeActivity.zR(SourceFile:575)
01-08 13:04:50.385: E/AndroidRuntime(13369): at com.android.mail.compose.ComposeActivity.onCreate(SourceFile:437)
01-08 13:04:50.385: E/AndroidRuntime(13369): at com.google.android.gm.ComposeActivityGmail.onCreate(SourceFile:54)
01-08 13:04:50.385: E/AndroidRuntime(13369): at android.app.Activity.performCreate(Activity.java:5133)
01-08 13:04:50.385: E/AndroidRuntime(13369): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
01-08 13:04:50.385: E/AndroidRuntime(13369): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
01-08 13:04:50.385: E/AndroidRuntime(13369): ... 11 more
干杯, 索拉夫
【问题讨论】:
添加intent.setType("text/plain");
嗨,Shayan 感谢您的投入。我添加了 intent.setType("message/rfc822") 但仍然得到相同的异常
你的链接上看到doreamon的回答了吗?
我什至试过这个。我没工作。意图 emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", "", null)); emailIntent.putExtra(Intent.EXTRA_SUBJECT,主题); emailIntent.putExtra(Intent.EXTRA_TEXT,正文); emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, attachments);
您是否记录了所有值,例如 to
和 subject
和 .. ?因为可能是其中之一
【参考方案1】:
请看一下
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]"upadhyay.jitesh@gmail.com");
// emailIntent.putExtra(android.content.Intent.EXTRA_BCC, new String[]etEmail.getText().toString());
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, getResources().getString(R.string.feedback_for)+"an interesting place");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, etComment.getText().toString()+"\n\n"+getResources().getString(R.string.rating)+rbRating.getRating()+"\n"+getResources().getString(R.string.my_contact_number)+etPhoneNumber.getText().toString());
startActivity(Intent.createChooser(emailIntent, getResources
().getString(R.string.chooser_send_feedback)));
请关注我的博客,对你有帮助
http://upadhyayjiteshandroid.blogspot.in/2013/03/android-using-e-mail-services-for.html
【讨论】:
但据我了解,“plain/text”类型的 action_send 将列出所有其他响应这种意图的应用程序 是的,它可以,所以我会找到另一个解决方案,如果我能得到并且会通知你 感谢 Jitesh...抱歉,如果我最初的问题不清楚...已更新以上是关于在 gmail android 应用程序中发送带附件的电子邮件时出错的主要内容,如果未能解决你的问题,请参考以下文章
使用 Gmail api 通过 Android 应用发送邮件