Integration‎ > ‎

SDK Free - Symbian


SubTutorials




This tutorial is intended to help developers integrate Vdopia mobile ads in Symbian applications. The tutorial shows how to add code needed to request and render ads developed using QT C++ Creator for Nokia.

Ad Fetch URL

To Start the integration you will need an Ad Fetch url to get Ad content from vdopia Ad server. this URL can be composed by your API Key ( from iVDOPIA Portal ), Ad Type and some other Ad parameters.

Syntax :

http://serve.vdopia.com/adserver/html5/adFetch/?output=xhtml;slide=0;sleepAfter=0;adFormat=[Ad Format];ak=[API Key];version=1.0;di=[DEVICE ID]

Sample URL :
http://serve.vdopia.com/adserver/html5/adFetch/?output=xhtml;slide=0;sleepAfter=0;adFormat=preappvideo;ak=AX123;version=1.0;di=a82sjd7182s291

Setting Up Project File ( .pro )

you need to append these line in the project file , which will allow you to use webkit, network access and other utilities.

QT += webkit network xml
CONFIG += mobility
MOBILITY += systeminfo
INCLUDEPATH += QSystemInfo

Integration

Assuming mainwindow.cpp as base app file .

Main Window Header file : MainWindow.h

Add void showAd and void createAdView(QString adText) in Private functions and create private slots void replyFinished(QNetworkReply *reply) and void finished(QNetworkReply *reply).

Sample Code :

private:
    Ui::MainWindow *ui;
    void showAd();
    void createAdView(QString adText);
    
void removeAd();

private
slots:
    void replyFinished(QNetworkReply *reply );
    void finished(QNetworkReply *reply);


Main Window file : MainWindow.cpp

Add these classes in header in MainWindow.cpp

#include <QtCore/QCoreApplication>
#include <QNetworkReply>
#include <QWebView>
#include <QXmlStreamReader>
#include <QSystemDeviceInfo>
QTM_USE_NAMESPACE

Copy paste these bellow functions in MainWindow.cpp file.


//API Parameters
QString apikey="AX123";
QString adFormat="preappvideo";
QString version="1.0";
QString slide="1";
QString sleepAfter="0";

QWebView
* view;
void MainWindow::showAd()
{
    qWarning("Get Ad from VDOPIA");
    QSystemDeviceInfo deviceInfo;
    QString url;
    url="http://serve.vdopia.com/adserver/html5/adFetch/?output=xhtml;"
    url+="slide="+slide+";sleepAfter="+sleepAfter+";adFormat="+adFormat+";ak="+apikey;
    url+=";version="+version+";di="+deviceInfo.imei().toUtf8();
    QNetworkAccessManager *manager = new QNetworkAccessManager(this);
    connect(manager, SIGNAL(finished(QNetworkReply*)),this, SLOT(replyFinished(QNetworkReply*)));
    manager->get(QNetworkRequest(QUrl(url)));
}

void
MainWindow::createAdView(QString adText)
{
    //Creating Web view here
    view = new QWebView(this);
    view->setContent(adText.toUtf8());
    view->resize(window()->width(),window()->height());
    view->setStyleSheet("background-color:#000000");
    view->show();
}

void MainWindow::removeAd()
{
    view->deleteLater();
}

void MainWindow::replyFinished(QNetworkReply *reply)
{
    qWarning("Ad xml Loaded");
QXmlStreamReader xml(reply->readAll());
QString adText;
while (!xml.atEnd()) {
         xml.readNext();
         if (xml.isStartElement()) {
             if (xml.name() == "xhtml")
             {
                 adText = xml.readElementText();
                 createAdView(adText);
             }
             else if(xml.name() == "errorCode")
                 {
                     // Error Code : 201 Invalid API Key
                     // Error Code : 202 Invalid Ad format Request
                     // Error Code : 203
Ad
not available
                 }
         }
     }
}

void MainWindow::finished(QNetworkReply *reply)
{
    qWarning("Ignore");
    QByteArray replyData(reply->readAll());
}

Load Ad

To load and Show Ad content you need to call showAd() function.

Remove Ad

To Remove Ad content , Please call removeAd() function.