Examples and code gotrough can be find also from Forum Nokia https://projects.developer.nokia.com/notificationsapi/wiki/qtapisample
The Notifications Client API is implemented as a Qt Plugin and is loaded by using the QPluginLoader mechanism. The following code shows how to load the Notifications API plugin and connect all the provided signal. One service object can be loaded per process / application id / session.
// ONE_PLUGIN_ABSOLUTE_PATH macro is added to the project when CONFIG+=ovinotifications is added in project's pro file. QPluginLoader *loader = new QPluginLoader(ONE_PLUGIN_ABSOLUTE_PATH); iNotificationSession = static_cast<OviNotificationSession *>(loader->instance()); delete loader; if (iNotificationSession) { // Connect signals to slots. connect(iNotificationSession,SIGNAL(stateChanged(QObject*)), this,SLOT(stateChanged(QObject*))); connect(iNotificationSession,SIGNAL(received(QObject*)), this,SLOT(received(QObject*))); connect(iNotificationSession,SIGNAL(notificationInformation(QObject*)), this,SLOT(notificationInfo(QObject*))); connect(iNotificationSession,SIGNAL(version(QString)), this,SLOT(versionResponse(QString))); }
To enable the application to receive notifications by default you only need to implement registerApplication function. To register the application with the Notifications Enabler, you use the registerApplication function, as shown below. When the session state changes, the OviNotificationSession::stateChanged signal is emitted; this signal returns the OviNotificationState object, which contains the application state. The state can be one of the following: online, offline, connecting.
iNotificationInterface->registerApplication(application_id); // In the stateChanged slot // State of the application has changed OviNotificationState* state = static_cast<OviNotificationState*>(aState); // Print out the session state on the screen switch (state->sessionState()) { case OviNotificationState::EStateOffline: { iTextConsole->append("Application is offline."); break; } case OviNotificationState::EStateOnline: { iTextConsole->append("Application is online."); break; } case OviNotificationState::EStateConnecting: { iTextConsole->append("Application is connecting."); break; } default: { break; } }
To retrieve the Notification ID, first connect to the notificationInformation signal, as shown below:
connect(serviceObject,SIGNAL(notificationInformation(QObject*)), this,SLOT(notificationInfo(QObject*)));
Then call the getNotificationInformation function on the session object, as shown below:
iNotificationInterface->getNotificationInformation(service_id);
When the Notification ID is fetched, the signal notificationInformation is emitted, and the corresponding slot is connected to the signal, as shown below:
// Cast QObject to OviNotificationInfo to access the methods OviNotificationInfo* info = static_cast<OviNotificationInfo*>(aData); QMessageBox messageBox; messageBox.setText("Notification Id"); messageBox.setInformativeText(info->notificationId()); messageBox.exec();
To receive a notification, your application must connect to the received signal (as explained above). OviNotificationMessage and OviNotificationPayload are then used to retrieve the notification:
// In the received slot OviNotificationMessage* notification = static_cast<OviNotificationMessage*>(aNotification); // Show the received notification in the screen OviNotificationPayload* payload = static_cast<OviNotificationPayload*>(notification->payload()); iTextConsole->append("Application " + notification->senderInformation() + "of the service "+notification->from() + " service sent: \n" + "'" + payload->dataString() + "'");
Copyright (C) 2010-2011 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. Contact: notifications.support@nokia.com This software, including documentation, is protected by copyright controlled by Nokia Corporation. All rights reserved. You may use this file only in accordance with the Nokia Developer Software Agreement version 2.0 and accompanying Ovi any additional terms. This material also contains confidential information which may not be disclosed to others without the prior written consent of Nokia. Nokia Developer Software Agreement version 2.0 and accompanying Ovi any additional terms |
MeeGo 1.2 Harmattan API
|