i am trying to detect new emails in inbox using subscribeToPullNotifications as follows:
PullSubscription subscription = service.subscribeToPullNotifications(
folder, 1, null, EventType.NewMail);
GetEventsResults events = subscription.getEvents();
System.out.println("####### EVENTS: "
+ events.getItemEvents().toString());
for (ItemEvent itemEvent : events.getItemEvents()) {
if (itemEvent.getEventType() == EventType.NewMail) {
EmailMessage message = EmailMessage.bind(service,
itemEvent.getItemId());
System.out.println("######## NEW EMAIL MESSAGE IS: "
+ message.getSubject());
}
}
but the events.getItemEvents()
is always empty, even i can see new emails in the inbox.
also how to make the above code is always repeated while the application is running, so that each minute it check for new emails.