Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
pfluger
Posts: 100
Registered: ‎02-10-2009
My Device: Q10, Z10
Accepted Solution

Intercepting calendar/SMS/E-Mail etc notifications?

I know how to add my own notifications to the profiles via NotificationsManager.registerSource, but is there a way to intercept those notifications from other programs (the ones you define in the Blackberry profiles)? I would be most interested in notifications triggered by the calendar app ("Calendar" and "Tasks" in the profiles).

 

I do not want to modify or cancel the original notification. I just want to know that it occurrs to log it.

 

I thought implementing and registering a NotificationsEngineListener would give me that information but I tried it and did not get anything at all, so I probably misunderstood this API?

 

Any help would be appreciated,

pfluger

Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Intercepting calendar/SMS/E-Mail etc notifications?

You are only notified for the deferred events that you create.
Developer
pfluger
Posts: 100
Registered: ‎02-10-2009
My Device: Q10, Z10

Re: Intercepting calendar/SMS/E-Mail etc notifications?

Thanks.

 

So how is an application like BBAlerts able to intercept several types of notifications (SMS, Mail, Calendar)? It will show them in a log and trigger its own LED/sound alert.

 

Or would the only way be to scan the PIM calendar and trigger my own notifications based on the alarm times. Does not sound very elegant...

 

Developer
madhurvyas1
Posts: 41
Registered: ‎08-05-2008
My Device: Not Specified

Re: Intercepting calendar/SMS/E-Mail etc notifications?

For calendar events you can use the PIMlistener, you will get notification in itemUpdated().
Developer
pfluger
Posts: 100
Registered: ‎02-10-2009
My Device: Q10, Z10

Re: Intercepting calendar/SMS/E-Mail etc notifications?

Great. This actually works! I implemented some test code and see the itemUpdated being fired.

 

Do you know what field of the event I would have to look for to see that itemUpdated is being called due to the alert being triggered?

Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Intercepting calendar/SMS/E-Mail etc notifications?

Applications like BBAlerts and AlertMatrix create their own customer alert profiles and fire these based on a folder event (email) or a datagram event (SMS), or whatever. They do not intercept the systems own "email notification".

 

Not the same thing as what you asked for.

 

 

 

 

Developer
pfluger
Posts: 100
Registered: ‎02-10-2009
My Device: Q10, Z10

Re: Intercepting calendar/SMS/E-Mail etc notifications?

I already dismissed the idea of being able to easily intercept notifications ;-)

 

Now I started doing the implementation as suggested. I started with the itemUpdated notification for calendar events as suggested by madhurvyas1.

 

The itemUpdate gets fired whenever an event occurs and whenever I click on 'Open' or 'Dismiss' in the event popup. My only problem is that I cannot see any hint at whether the call is because of the event being triggered or dismissed.

 

I have a function that prints all information about the oldItem and newItem passed to itemUpdated function. Both are exactly the same in every field/attribute/category. Does this equality only occurr in itemUpdated when the reminder is being fired? Is there any info that I am missing?

 

public void itemUpdated(PIMItem oldItem, PIMItem newItem ) {
System.out.println( "Old item " + oldItem.toString() );
System.out.println( "New item " + newItem.toString() );
printPIMItem( oldItem );
printPIMItem( newItem );
}

private void printPIMItem( PIMItem item ) {
int fields[] = item.getFields();
// PIMList events = item.getPIMList();
try {
net.rim.blackberry.api.pdap.BlackBerryEventList events = (net.rim.blackberry.api.pdap.BlackBerryEventList)PIM.getInstance().openPIMList(PIM.EVENT_LIST, PIM.READ_WRITE);
for( int i = 0; i < fields.length; i ++ ) {
System.out.println( " " + events.getFieldLabel(fields[i]) );
for( int j = 0; j < item.countValues(fields[i]); j ++ ) {
if( events.getFieldDataType(fields[i]) == PIMItem.INT ) {
System.out.println( " " + item.getInt(fields[i], j));
} else if( events.getFieldDataType(fields[i]) == PIMItem.STRING ) {
System.out.println( " " + item.getString(fields[i], j));
} else if( events.getFieldDataType(fields[i]) == PIMItem.BOOLEAN ) {
System.out.println( " " + item.getBoolean(fields[i], j));
} else if( events.getFieldDataType(fields[i]) == PIMItem.DATE ) {
System.out.println( " " + item.getDate(fields[i], j));
} else {
System.out.println( " unknown data type " + events.getFieldDataType(fields[i]));
}
int attributes = item.getAttributes(fields[i], j);
if( attributes != item.ATTR_NONE ) {
System.out.println( " attributes " + attributes );
}
String cats[] = item.getCategories();
for( int k = 0; k < cats.length; k ++ ) {
System.out.println( " category " + cats[k] );
}
}
}
} catch( Exception e ) {
System.out.println( "Failed printing PIMitem " + e.getMessage() );
}
}

 

This is a sample output I get:

 

Old Entry net.rim.blackberry.api.pdap.EventImpl@60278860
New Entry net.rim.blackberry.api.pdap.EventImpl@ad5e130a
 UID
  1148435429499247015
 Subject
  Test
 Reminder
  900
 End
  1234378140000
 Start
  1234374540000
 UID
  1148435429499247015
 Subject
  Test
 Reminder
  900
 End
  1234378140000
 Start
  1234374540000

 


 

Developer
madhurvyas1
Posts: 41
Registered: ‎08-05-2008
My Device: Not Specified

Re: Intercepting calendar/SMS/E-Mail etc notifications?

Hi,

 

What difference it makes if user clicks on dismiss or open, in both cases the calander item has fired. I think if user opens the item & changes something you should get another itemupdated call. 

I dont know the exact requirements of yours mine was to only get notified when the calander event is fired.

 

 

Developer
pfluger
Posts: 100
Registered: ‎02-10-2009
My Device: Q10, Z10

Re: Intercepting calendar/SMS/E-Mail etc notifications?

So how did you make sure the itemUpdated call was because of calendar a event fired and not because of a change in the calendar? 

 

I want to do a custom LED notification for the calendar event. This is why I need to know when the event popup has been closed so I can stop the LED.

Developer
madhurvyas1
Posts: 41
Registered: ‎08-05-2008
My Device: Not Specified

Re: Intercepting calendar/SMS/E-Mail etc notifications?

Hi,

If the event is modified the start & end time should be changed in the new event. If both are same then the event has not been changed.

I didnt try this but you can.