0

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

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

非常感谢你。

4

1 回答 1

1

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

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

于 2013-03-04T12:19:12.053 回答