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

Native Development

Reply
Developer
AlexXF
Posts: 323
Registered: ‎03-10-2010
My Carrier: Vodafone CZ
Accepted Solution

notification_alert() -- where i'm wrong?

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?

Please use plain text.
Developer
BGmot
Posts: 1,061
Registered: ‎11-24-2011
My Carrier: x

Re: notification_alert() -- where i'm wrong?

what if you remove render()?

// render();
Please use plain text.
Developer
AlexXF
Posts: 323
Registered: ‎03-10-2010
My Carrier: Vodafone CZ

Re: notification_alert() -- where i'm wrong?

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...

Please use plain text.
Developer
BGmot
Posts: 1,061
Registered: ‎11-24-2011
My Carrier: x

Re: notification_alert() -- where i'm wrong?

Just a guess - probably you should not destroy message prior to cancelling notification:

// notification_message_destroy(&pMessage);
Please use plain text.
Developer
AlexXF
Posts: 323
Registered: ‎03-10-2010
My Carrier: Vodafone CZ

Re: notification_alert() -- where i'm wrong?

No, it does not helps too.

Please use plain text.
Developer
BGmot
Posts: 1,061
Registered: ‎11-24-2011
My Carrier: x

Re: notification_alert() -- where i'm wrong?

I know, it's not funny.. but probably you are missing 

notification_request_events(0)

in main() prior to trying to notify?

Please use plain text.
Developer
AlexXF
Posts: 323
Registered: ‎03-10-2010
My Carrier: Vodafone CZ

Re: notification_alert() -- where i'm wrong?

[ Edited ]

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.

Please use plain text.
BlackBerry Development Advisor
lingBB10Dev
Posts: 35
Registered: ‎08-01-2012
My Carrier: T-Mobile

Re: notification_alert() -- where i'm wrong?

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/reference/com.qnx.doc.bps.lib_ref/com.qnx.doc.bps.lib_r...

 

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.

 

Please use plain text.
Developer
AlexXF
Posts: 323
Registered: ‎03-10-2010
My Carrier: Vodafone CZ

Re: notification_alert() -- where i'm wrong?

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;

    }

 

Please use plain text.
Developer
AlexXF
Posts: 323
Registered: ‎03-10-2010
My Carrier: Vodafone CZ

Re: notification_alert() -- where i'm wrong?

Can you attach example of WORKING code? 

Please use plain text.