首页 » 黑莓开发 » 监听所有邮件账号下的新邮件

监听所有邮件账号下的新邮件

6016 2

BBextra 1.06用的是监听默认邮件账号下的新邮件,因为一开始本人用的是shangmail代理转发接收所有的邮件,因此设备上只有一个邮件账号,即默认的账号,所以没发生问题。之后上了BIS后,直接通过BIS加了公司的,以及gmail的邮箱后,并将公司邮箱设置成默认账号,这时才发现当gmail的邮件收到新邮件时,BBe的新邮件到达设置并不会起作用,只有公司账号下的新邮件才有效。因此觉得有必要调整一下下一个版本的代码,使BBe能支持设备上所有的邮件账号。

将原先的代码:

      //Get the store from the default instance.
      Store store = Session.getDefaultInstance().getStore();
      //Add the folder listener to the store.
      store.addFolderListener(this);

调整为以下代码:

ServiceBook sb = ServiceBook.getSB();
ServiceRecord[] srs = sb.getRecords();
for(int cnt = srs.length - 1; cnt >= 0; --cnt) {
//identify the service record associated with a mail message service via a CID of 'CMIME'
if( srs[cnt].getCid().equals( "CMIME" )) {
ServiceConfiguration sc = new ServiceConfiguration(srs[cnt]);
Store store = Session.getInstance(sc).getStore();
store.addFolderListener(this);
}
}
通过判断servicebook中CID带有CMIME的条目来获得相关的邮件账号,并给每个store,加上监听器。

文章评分1次,平均分5.0

本文原始地址:https://www.tiandiyoyo.com/2011/09/how-to-detect-incoming-email/
本站所有文章,除了特别注明外,均为本站原创,转载请注明出处来自www.tiandiyoyo.com

您可能还会对以下文章感兴趣:

评论前先开启评论开关:


2 Comments

  1. Faris :

    貌似很不错~~学习了~~~对了,有个错别字“这是才发现”—-“这时才发现”

载入分页评论...