09-05-2012 02:04 PM
void showNotification()
{
notification_message_t* pMessage = NULL;
if (notification_message_create(&pMessage) != BPS_SUCCESS) {
fprintf(stderr, "Unable to create notification_message_t\n");
return;
}
if(notification_message_set_item_id(pMessage,"test _my_notification")!=BPS_SUCCESS)
{
fprintf(stderr, "Unable to notification_message_set_item_id\n");
notification_message_destroy(&pMessage);
return;
}
if (notification_message_set_app_id(pMessage, "com.example.HelloWorldDisplay") != BPS_SUCCESS) {
fprintf(stderr, "Unable to notification_message_set_app_id\n");
notification_message_destroy(&pMessage);
return;
}
if(notification_message_set_title(pMessage, "Test title") != BPS_SUCCESS)
{
fprintf(stderr, "Unable to notification_message_set_title\n");
notification_message_destroy(&pMessage);
return;
}
if(notification_message_set_subtitle(pMessage, "Message text") != BPS_SUCCESS)
{
fprintf(stderr, "Unable to notification_message_set_subtitle\n");
notification_message_destroy(&pMessage);
return;
}
if(notification_message_set_type(pMessage, "Protect") != BPS_SUCCESS)
{
fprintf(stderr, "Unable to notification_message_set_type\n");
notification_message_destroy(&pMessage);
return;
}
if(notification_alert(pMessage) != BPS_SUCCESS)
{
fprintf(stderr, "Unable to notification_alert\n");
notification_message_destroy(&pMessage);
return;
}
fprintf(stderr, "Notification must be shown\n");
notification_message_destroy(&pMessage);
}
int main(int argc, char **argv) {
//Create a screen context that will be used to create an EGL surface to to receive libscreen events
screen_create_context(&screen_cxt, 0);
//Initialize BPS library
bps_initialize();
//Use utility code to initialize EGL for rendering with GL ES 1.1
if (EXIT_SUCCESS != bbutil_init_egl(screen_cxt)) {
fprintf(stderr, "Unable to initialize EGL\n");
screen_destroy_context(screen_cxt);
return 0;
}
//Initialize app data
if (EXIT_SUCCESS != init()) {
fprintf(stderr, "Unable to initialize app logic\n");
bbutil_terminate();
screen_destroy_context(screen_cxt);
return 0;
}
//Signal BPS library that navigator orientation is to be locked
if (BPS_SUCCESS != navigator_rotation_lock(true)) {
fprintf(stderr, "navigator_rotation_lock failed\n");
bbutil_terminate();
screen_destroy_context(screen_cxt);
return 0;
}
//Signal BPS library that navigator and screen events will be requested
if (BPS_SUCCESS != screen_request_events(screen_cxt)) {
fprintf(stderr, "screen_request_events failed\n");
bbutil_terminate();
screen_destroy_context(screen_cxt);
return 0;
}
if (BPS_SUCCESS != navigator_request_events(0)) {
fprintf(stderr, "navigator_request_events failed\n");
bbutil_terminate();
screen_destroy_context(screen_cxt);
return 0;
}
showNotification();
for (;;) {
//Request and process BPS next available event
bps_event_t *event = NULL;
if (BPS_SUCCESS != bps_get_event(&event, 0)) {
fprintf(stderr, "bps_get_event failed\n");
break;
}
if ((event) && (bps_event_get_domain(event) == navigator_get_domain())
&& (NAVIGATOR_EXIT == bps_event_get_code(event))) {
break;
}
render();
}
//Stop requesting events from libscreen
screen_stop_events(screen_cxt);
//Shut down BPS library for this process
bps_shutdown();
//Destroy the font
bbutil_destroy_font(font);
//Use utility code to terminate EGL setup
bbutil_terminate();
//Destroy libscreen context
screen_destroy_context(screen_cxt);
return 0;
}
I'm trying to display notification in test application (example 'HelloWorld (console)'), but there is no notification shown. Where i'm wrong? What i've miss?
Solved! Go to Solution.
09-05-2012 02:17 PM
what if you remove render()?
// render();
09-05-2012 02:26 PM
No. It does not helps. No any notifications shown.
There is no example, so i do not understand - where i'm wrong. All looks good, but...
09-05-2012 02:39 PM
Just a guess - probably you should not destroy message prior to cancelling notification:
// notification_message_destroy(&pMessage);
09-05-2012 02:42 PM
No, it does not helps too.
09-05-2012 02:50 PM
I know, it's not funny.. but probably you are missing
notification_request_events(0)
in main() prior to trying to notify?
09-05-2012 02:55 PM - edited 09-05-2012 03:05 PM
Does not matter. Trying to add notification_request_events(0), but this is not helps. This function needs if i need to process user responce on notify.
09-10-2012 10:13 AM
Hi AlexXF,
When I inserted "notification_message_add_prompt_choice()" in your code before calling
notification_alert(), I was able to trigger a notification dialog appear.
According to https://developer.blackberry.com/native/beta/refer
notification_message_set_title() itself shall be enough to trigger a toast message( did not work for me as well)
We are consulting our internal contact to get clarification for the conditions of triggering a toast message for notication.
09-11-2012 08:38 AM
I'm using NDK Beta 2 (10.0.6) and Firmware 10.0.6.545.
If I add this code before notification_alert it does not helps.
if(notification_message_add_prompt_choice(pMessage, "Ok", NULL)!=BPS_SUCCESS) { fprintf(stderr, "Unable to notification_message_set_type\n"); notification_message_destroy(&pMessage); return; } if(notification_alert(pMessage) != BPS_SUCCESS) { fprintf(stderr, "Unable to notification_alert\n"); notification_message_destroy(&pMessage); return; }
09-12-2012 01:52 AM
Can you attach example of WORKING code?