Qt-based BB10 API Examples Documentation

Contents

Notifications Example

Files:

Description

The Notifications example demonstrates how to use the notification framework of BB10 to inform the user about certain events.

Overview

In this example we'll learn how to use the Notification and NotificationDialog classes, as provided by the BB framework, to notify the user about important events from our application.

UI

The UI of this sample application consists of three Buttons. The first one sends a notification, the second one shows a dialog and the third one clears all notifications of the application.

    attachedObjects: [
        Notification {
            id: notification
            title: qsTr ("TITLE")
            body: qsTr ("BODY")
            soundUrl: _publicDir + "system_battery_low.wav"
        },
        NotificationDialog {
            id: notificationDialog
            title: qsTr ("TITLE")
            body: qsTr ("BODY")
            soundUrl: _publicDir + "system_battery_low.wav"
            buttons : [
                SystemUiButton {
                    label: qsTr ("Okay")
                }
            ]
            onFinished: {
                console.log("Result: " + result);
                console.log("Error: " + error);
            }
        }
    ]

The main page contains a Notification and a NotificationDialog object as 'attachedObjects'. These two objects provides access to the notification system of the BB10 platform. Both objects are configured with a title, a body text and a sound URL.

    Button {
        horizontalAlignment: HorizontalAlignment.Center

        text: qsTr("Notification")
        onClicked: {
            notification.notify();
        }
    }

If the user clicks on the 'Notification' button, the 'notify()' method of the Notification object is invoked.

    Button {
        horizontalAlignment: HorizontalAlignment.Center
        topMargin: 50

        text: qsTr("Notification Dialog")
        onClicked: {
            notificationDialog.show();
        }
    }

If the user clicks on the 'Notification Dialog' button, the 'show()' method of the NotificationDialog object is invoked, which will bring up a dialog on top of the application window.

    attachedObjects: [
        Notification {
            id: notification
            title: qsTr ("TITLE")
            body: qsTr ("BODY")
            soundUrl: _publicDir + "system_battery_low.wav"
        },
        NotificationDialog {
            id: notificationDialog
            title: qsTr ("TITLE")
            body: qsTr ("BODY")
            soundUrl: _publicDir + "system_battery_low.wav"
            buttons : [
                SystemUiButton {
                    label: qsTr ("Okay")
                }
            ]
            onFinished: {
                console.log("Result: " + result);
                console.log("Error: " + error);
            }
        }
    ]

If the user clicks on the 'Clear All Notifications' button, the 'clearEffectsForAll()' method of the Notification object is invoked. This clears all the notification effects (e.g. blinking LED, marker on application icon etc.) of this application.

        qmlRegisterType<bb::system::SystemUiButton>("bb.system", 1, 0, "SystemUiButton");
        qmlRegisterType<bb::platform::Notification>("bb.platform", 1, 0, "Notification");
        qmlRegisterType<bb::platform::NotificationDialog>("bb.platform", 1, 0, "NotificationDialog");
        qmlRegisterUncreatableType<bb::platform::NotificationError>("bb.platform", 1, 0, "NotificationError", "");
        qmlRegisterUncreatableType<bb::platform::NotificationResult>("bb.platform", 1, 0, "NotificationResult", "");

To be able to use the Notification and NotificationDialog objects inside the QML file, we have to register them inside our App object.