Android - 从应用程序发送电子邮件
我在从 Android 应用程序发送电子邮件时遇到问题。它间歇性地工作且不可靠。大多数时候,它停留在发件箱中,处于“正在发送..”状态。
我知道这是一个经常重复的问题,但我再次问它,因为我已经尝试了相当多的代码变体,但它们似乎都不能可靠地工作。一些论坛还说这是 GMail 应用程序的错;我尝试过“刷新发件箱文件夹”和“禁用和启用同步”,但似乎没有任何效果。
这是我的代码:
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "emailText");
emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
emailIntent.setType("application/zip");
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File("/mnt/sdcard/myFolder/myFile.zip")));
startActivity(Intent.createChooser(emailIntent, "send email"));
finish();
- 有人可以解释为什么这不起作用吗?
- setType() 的值应该是多少?在哪里可以找到可用值的列表?
- 是因为我正在尝试发送 .zip 文件吗?如果是这样,其他存档格式也可以吗?
非常感谢您的帮助。
编辑:我怀疑问题出在文件格式(.zip)上。其他文件格式也可以正常工作。我已经放弃了这种方法,转而使用 TCP,用我自己的服务器监听数据。
I am facing problems in sending email from an Android app. It works intermittently and unreliably. Most of the times, it is stuck in Outbox, in 'Sending..' state.
I know this is a oft-repeated question here, but I am asking it again because I have tried quite a few variations in code, and none of them seem to work RELIABLY. Some forums also say that this is GMail app's fault; and I have tried 'refreshing the outbox folder' and 'disabling and enabling sync', but nothing seems to do the trick.
Here is my code:
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "emailText");
emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
emailIntent.setType("application/zip");
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File("/mnt/sdcard/myFolder/myFile.zip")));
startActivity(Intent.createChooser(emailIntent, "send email"));
finish();
- Could someone explain why wouldn't this work?
- What should be the value for setType()? Where can I find a list of available values?
- Is it because I am trying to send a .zip file? If so, would other archive formats work?
Thanks a lot for your help.
EDIT: I suspect that the issue is with file format (.zip). Other file formats work just fine. I have abandoned this approach and gone for TCP with my own server listening for data.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它可能卡在发送状态的原因是因为根据 zip 文件的 SIZE,它必须将其添加到电子邮件中。如果它太大(超过 30 MB),它可能会挂起并被谷歌拒绝,因为谷歌不允许在电子邮件中发送超过 30MB 的内容。这只是一个猜测,但请尝试发送一个小文件,看看是否是这种情况。
The reason why it could be stuck in the sending state is because depending on the SIZE of the zip file, it has to add it to the email.. If its too large (over 30 MB) it might hang and get denied by google, since google does not allow the sending of over 30MB in an email. This is just a guess, but try sending a small file and see if this is the case.