AddFolderListener适用于某些设备,但在另一台设备中不起作用

时间:2013-02-15 08:40:08

标签: java blackberry directory listener

我正在开发一个应用程序,用于侦听来自电子邮件帐户的邮件,并执行特定操作。为此,我用这个:

public class EmailListener implements FolderListener {

public void registerEmailListener(boolean register) {
ServiceBook sb = ServiceBook.getSB();
ServiceRecord[] srs = sb.findRecordsByCid("CMIME");
if (srs != null) {
ServiceRecord sr;
ServiceConfiguration sc;
/* unregister all email listener  to avoid duplicate listeners */
desregisterAllEmailListeners(srs);
for (int i = srs.length - 1; i >= 0; --i) {
sr = srs[i];
try {
sc = new ServiceConfiguration(sr);
registerEmail(sc, register);

} catch (Exception e) {
e.printStackTrace();
}
}

}
}

private void registerEmail(ServiceConfiguration sc, boolean register) {
Session s = Session.getInstance(sc);
if (s != null) {
Folder[] folders = s.getStore().list();
for (int foldercnt = folders.length - 1; foldercnt >= 0; --foldercnt) {
Folder f = folders[foldercnt];
// If the folder doesn't have the service book for this email, we do not want to register it
if (f.getFullName().indexOf(sc.getEmailAddress()) >= 0) {
recurse(f, register);
}
}
} 
}
private void recurse(Folder f, boolean add) {
if (f.getType() == Folder.INBOX) {

f.removeFolderListener(this);
if (add) {
f.addFolderListener(this);
}
}
Folder[] farray = f.list();
for (int fcnt = farray.length - 1; fcnt >= 0; --fcnt) {
recurse(farray[fcnt], add);
}
}

public void desregisterAllEmailListeners(ServiceRecord[] srs) {
ServiceRecord sr;
ServiceConfiguration sc;
for (int i = srs.length - 1; i >= 0; --i) {
sr = srs[i];
try {
sc = new ServiceConfiguration(sr);
registerEmail(sc, false);
} catch (Exception e) {
e.printStackTrace();
}
}
}

public void messagesAdded(final FolderEvent e) {

....

}

....

}

当电子邮件到来时,它会执行messageAdded并执行特定操作。问题是在某些设备中它起作用,而在另一个设备中起作用。它会在每种情况下正确注册电子邮件侦听器,但在某些情况下不会执行messageAdded。 这个问题到底是什么?

适用于:9300 OS 6.0和OS 5.0以及9220 OS 7.1 它在9320 OS 7.1,9380 OS 7.1和9800 OS 6.0中不起作用

非常感谢。

1 个答案:

答案 0 :(得分:1)

是!!,它执行messageAdded ....调试。我不知道为什么不在某些设备上显示日志....

道德是: 不要只相信logEvent,使用这个和调试工具,两个!!