android - 下载前以编程方式获取 Gmail 附件大小

标签 android email-attachments

我正在使用 Multipart/Bodypart 概念下载我的 Gmail 附件。 下载正常并且工作正常。但在实际下载文件之前无法获取附件大小。

这里是代码 fragment :

Store store = s.getStore("imaps");
store.connect("imap.gmail.com", "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f994809e94989095989d9d8b9c8a8ab99e94989095d79a9694" rel="noreferrer noopener nofollow">[email protected]</a>", "password");
Folder inbox = store.getFolder("Misc");
inbox.open(Folder.READ_ONLY);
Message[] msgs = inbox.getMessages();
Multipart m=(Multipart)msgs[inbox.getMessageCount()-1].getContent(); //taking latest email
for(int i = 0;i < m.getCount(); i++){
BodyPart bp = m.getBodyPart(i);
String disposition = bp.getDisposition();
if(disposition!=null &&(disposition.equals("ATTACHMENT"))){
/*downloading code here */
}
}

如何在实际下载之前获取附件大小?

最佳答案

试试这个:

ByteArrayOutputStream os = new ByteArrayOutputStream();
                m.writeTo(os);
                int bytes = os.size();

关于android - 下载前以编程方式获取 Gmail 附件大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17759666/

相关文章:

android - 无法将 pdf.js 查看器用于本地文件 ://on Android, 适用于 iOS

android - 对话框在是按钮上关闭

java - SharedPreferences:为什么我的值没有被覆盖?

asp.net-mvc-4 - 使用 SmtpClient 的 MVC 4.5 : Send an email with . pdf 附件 - 我在这里缺少什么?

android: ImageView 不显示来自 URL 的位图

c# - 如何发送没有扩展名的文件附件的电子邮件?

Android 应用程序已分配给任何可能的文件 - 应仅分配给我的自定义文件

python-2.7 - 属性错误: list object has not attribute lstrip in sending an email with attachment

email - 将iCalendar事件附加到Grails中的邮件

android - 比较堆转储 (HPROF) 文件