×
Namespaces

Variants
Actions

Archived:Using Notification API in GPS based application

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Compatibility
Platform(s):
Symbian
Article
Created: aj4mobile (06 Mar 2011)
Last edited: hamishwillee (21 Nov 2013)

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

Qt Notification API deprecated.

Contents

Introduction

Qt, the cross-platform application and UI framework, has newly introduced Notifications API, a striking feature which helps in adding real-time push notifications. Notifications API is highly efficient as it delivers light-weight notifications optimizing bandwidth and battery usage. Mobile application development is in its revolutionary stage now; server-initiated push messages to the mobile client are an inevitable factor here, which has been employed by Qt in the new beta release. Notifications API enables clients to obtain instantaneous notifications for email, facebook, twitter, weather updates, stock updates, etc even when the applications are not active. In this article, I hereby elucidate yet another applicability of Notification API using GPS.


Goals and objectives:

To utilize Notifications API and develop a real-time sticky application within hours with minimal development effort.


Problem statement:

Situations arise when people need to be traced in order to find out their exact location in emergencies. Such situations can be met by introducing a GPS application using Notifications API which helps to track a person who is registered to the server by another person who is also registered and connected with the former. This helps in circumstances where the former is not in a position to respond, but needs to be traced where he/she is.


Strategy:

A client side application is developed which retrieves latitudes/longitudes and receives messages from the back end server. The notifications support can be provided by using Notifications Qt API. QT Mobility Location API can be used to get latitude & longitude. Develop a back end server which enables user registration, authentication, sending message to the requested user. This server sends the message to the mobile by using Notifications Service API. The Notification Service API provides access to the Notification Server through an HTTP REST interface.


Why Qt:

Notification implementation using a third party SMS gateway server to send message to mobile is a costly process.

The push mechanism used in Blackberry phones using Blackberry Enterprise Service is highly expensive.

Even though Apple push notification service works similar to Qt, the ease with which development can be done in Qt Quick makes it an all-time favorite. Moreover, it does not need a specific platform for development unlike the iPhone development which can be done only in Mac environment.

Android also lags behind Qt Quick in developmental ease and it is not available universally.


Resource requirement:

- A mobile application which supports Qt SDK 1.1 (Beta)

- Internet connectivity in the mobile

- A public IP server machine

- A developer


How this app works:

This application helps registered clients to track their geographical positions even if they are not in a situation to respond to messages. A client who is registered to the server can access other clients who are also linked with the server and who have enabled tracing by the former. When the client requests for tracking of another client, the server sends a message via Notification API to the latter’s phone, and the latter responds by sending the current longitudinal and latitudinal position. This message hits the server again, and the server pushes it to the former who initiated the request. The positions are evoked in a map in the former’s mobile, denoting the exact geographical position of the latter. Any registered user is entitled to enable or disable the tracking facility according to their wish.


A Guide towards implementation of the application:

Implementing the project is quite simple since all the needed resources are available in Nokia Developer and Qt Nokia website itself.

Client Application:

The client application consists of three modules viz. UI, latitudes and longitudes retrieval and notification listener.

The UI for the mobile application can be easily created using QT Quick. Many samples are available which comes along with SDK. The developer shall cull out desired samples and develop accordingly.

The latitude and longitudes retrieval source code is given here

void MainWindow::startGPS()
{
// Obtain the location data source if it is not obtained already
if (!locationDataSource)
{
locationDataSource =
QGeoPositionInfoSource::createDefaultSource(this);
if (locationDataSource)
{
// Whenever the location data source signals that the current
// position is updated, the positionUpdated function is called.
QObject::connect(locationDataSource,
SIGNAL(positionUpdated(QGeoPositionInfo)),
this,
SLOT(positionUpdated(QGeoPositionInfo)));
// Start listening for position updates
locationDataSource->startUpdates();
} else {
// Not able to obtain the location data source
// TODO: Error handling
}
} else {
// Start listening for position updates
locationDataSource->startUpdates();
}
}
 
void MainWindow::positionUpdated(QGeoPositionInfo geoPositionInfo)
{
if (geoPositionInfo.isValid())
{
// Stop regular position updates, because a valid position has been
// obtained
locationDataSource->stopUpdates();
 
// Get the current location as latitude and longitude
QGeoCoordinate geoCoordinate = geoPositionInfo.coordinate();
qreal latitude = geoCoordinate.latitude();
qreal longitude = geoCoordinate.longitude();
 
// Fetch the map using the display size and the coordinates
QUrl url = createGoogleMapURL(size(), latitude, longitude);
webView->stop(); // Stop the ongoing request
webView->load(url); // Load the Google Map
}
}
 
QUrl MainWindow::createGoogleMapURL(const QSize& size, qreal latitude,qreal longitude)
{
const QString GOOGLE_MAPS_URL_TEMPLATE =
"http://maps.google.com/maps/api/staticmap?center=%1,%2&zoom=12&size=%3x%4&maptype=mobile&markers=color:red|label:Y|%1,%2&sensor=true";
QUrl url = QUrl(GOOGLE_MAPS_URL_TEMPLATE.arg(
QString::number(latitude), QString::number(longitude),
QString::number(size.width()), QString::number(size.height())));
return url;
}
Instantiate QWebView() as below and invoke startGPS() from your application module.
webView = new QWebView(this);
// Start the GPS
startGPS();

It can be referred in the link: http://www.developer.nokia.com/document/Mobile_Hands-on_Labs/Qt/MobilityLocation/05.html. The file QtMobilityLocation.zip shall be downloaded, opened in Qt SDK 1.1 (Beta), the code is copied and appended to the project.


For registering & unregistering the application for the notification

void NotificationExample::registerApplication()
{
// Register to Notifications
iTextConsole->append("Registering to Notifications ...");
iNotificationInterface->registerApplication(application_id);
}
 
void NotificationExample::unregisterApplication()
{
// Unregister from Notifications
iTextConsole->append("Unregistering from Notifications...");
iNotificationInterface->unregisterApplication();
}

The code for receiving notification message in the application is given below. This can be customized in such a way that on receiving the notification message, the application invokes the latitudinal & longitudinal values as explained above.

void NotificationExample::received(QObject* aNotification)
{
// Casting the QObject to OviNotificationMessage to gain access
// to all its members.
OviNotificationMessage* notification =
static_cast<OviNotificationMessage*>(aNotification);
 
// Show the received notification in the screen
OviNotificationPayload* payload = static_cast<OviNotificationPayload*>(notification->payload());
 
iTextConsole->setText("Notification received!");
iTextConsole->append("Application " + notification->senderInformation()
+ " of the service "+notification->from()+ " service sent: \n"
+ "'" + payload->dataString() + "'");
// Printing out the notification details in text console. Optional.
iTextConsole->append("Notification received.");
iTextConsole->append("Notification was sent at " + notification->timestamp());
if (!payload->type().isEmpty())
{
iTextConsole->append("Payload type was set to " + payload->type());
}
if (!payload->encoding().isEmpty())
{
iTextConsole->append("Payload was encoded in " + payload->encoding());
}
 
delete notification;
}

Back end server application:

The developer can develop a simple server side application in his choice of platform. The server sends message to mobile via Notifications API.


Conclusion:

There were many social networking sites which came into being before Facebook. But none of them were as successful as Facebook. This shows that the time of introduction doesn't matter, the uniqueness in expression of ideas is what that matters. Similarly, the above application developed using Qt framework and Notifications API shall stretch its wings beyond the horizons.

References:

http://www.developer.nokia.com/

http://developer.qt.nokia.com/prereleases

http://qt.gitorious.org/

http://qt.nokia.com/qtquick/

This page was last modified on 21 November 2013, at 12:57.
86 page views in the last 30 days.