本文介绍了清单用JavaMail API收件箱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我得到收件箱文件夹我的Gmail帐户,可以列出来的电子邮件,但该名单是从旧的邮件中列出到新邮件。我怎么能恢复呢?
公共类readInbox扩展ListActivity {/ **当第一次创建活动调用。 * /
@覆盖
公共无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
//setContentView(R.layout.readmail);留言[] =的消息新的消息[] {};尝试{
消息= inboxReader.getMail();
}
赶上(MessagingException E){
Log.e(邮件阅读getMail错误readmail.java。e.getMessage(),E);
}ArrayAdapter<消息>适配器=新ArrayAdapter<消息>(这一点,
R.layout.simple_list_item_1,消息){
@覆盖
公共查看getView(INT位置,查看convertView,父母的ViewGroup){
消息消息=的getItem(位置);
TextView的resultView =新的TextView(super.getContext());
尝试{
resultView.setText(message.getSubject());
}
赶上(MessagingException E){
Log.e(resultView.setText在readmail,e.getMessage(),E);
}
返回resultView;
}
};setListAdapter(适配器);
}
}
解决方案
您可以通过 inbox.getMessageCount获取消息的总数()
,然后检索最后N号的消息。
留言信息[] = inbox.getMessages(inbox.getMessageCount() - 25,inbox.getMessageCount());
I'm getting inbox folder of my gmail account, can list the incoming e-mails, but that list is being listed from older mails to newer mails. How can i revert that ?
public class readInbox extends ListActivity{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
//setContentView(R.layout.readmail);
Message[] messages = new Message[] { };
try {
messages = inboxReader.getMail();
}
catch (MessagingException e) {
Log.e("mailReader getMail error. in readmail.java", e.getMessage(), e);
}
ArrayAdapter<Message> adapter = new ArrayAdapter<Message>(this,
R.layout.simple_list_item_1 ,messages){
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Message message = getItem(position);
TextView resultView = new TextView(super.getContext());
try {
resultView.setText(message.getSubject());
}
catch (MessagingException e) {
Log.e("resultView.setText in readmail", e.getMessage(), e);
}
return resultView;
}
};
setListAdapter(adapter);
}
}
解决方案
You can get the total number of messages through inbox.getMessageCount()
, then retrieve last N number of messages.
Message messages[] = inbox.getMessages(inbox.getMessageCount() - 25 , inbox.getMessageCount());
这篇关于清单用JavaMail API收件箱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!