1
我在我的android项目中使用了javamail api,并在“邮件主题”和“邮件内容”中解析字符串。在我的Gmail中,有许多邮箱,例如旅行,工作,照片......我需要通过所有邮箱和搜索邮件查看我的情况。但是我发现当调用getData()它会登录gmail并重新建立连接。如何在android中保持javamail连接?
我的问题是
1.如何在android中保持连接?
2.如何在同一时间搜索所有邮箱?
感谢您的帮助。
private String downloadUrl() throws IOException {
receiveMail("username", "password");
return null;
}
receiveMail部分
private static List<Message> receiveMail(String username, String Password) {
try {
Properties props = System.getProperties();
props.setProperty("mail.store.protocol", IMAPS_PROTOCOL);
Session session = Session.getDefaultInstance(props, null);
session.setDebug(false);
final Store store = session.getStore(IMAPS_PROTOCOL);
store.connect(IMAPS_MAIL_HOTS , username, Password);
getData(store, "travel");
getData(store, "job");
getData(store, "photo");
} catch(Exception ex) {
ex.printStackTrace();
}
return null;
}
更新: 但是,我有一个新问题。我将getData()放入线程中,以便在同一时间搜索所有邮箱。似乎不能等到在打开下一个文件夹之前关闭文件夹。 我该怎么办?谢谢 – Louis