×
Namespaces

Variants
Actions

Integrating Vserv Ads in Nokia X

From Nokia Developer Wiki
Jump to: navigation, search
Featured Article
18 May
2014

This article explains how to integrate Vserv Ads into Nokia X application using the Vserv Android SDK.

Note.pngNote: This article was a winning entry in the Nokia X Wiki Challenge 2014Q1

Article Metadata
Code Example
Source file: Media:Vservads.zip
Tested with
Devices(s): NOKIA X Emulator
Platform Security
Capabilities: ACCESS_NETWORK_STATE
Article
Created: pardeepsharma10 (13 Apr 2014)
Last edited: BuildNokia (02 Jun 2014)


Contents

Introduction

The Vserv Ad Network provides Advertisement support to almost all mobile platforms, including Nokia X - the newest addition to the Nokia family. I will use the Vserv Android SDK for integration. This can be performed by following the steps described below.

Implementation

Register as Developer

First, you'll need a Developer Account. If you don't have one, register as a developer on the Vserv site. Your Default Zone ID will be sent to you in your welcome email. I will use my Default Zone ID in the sample, but you can create as many Zone IDs as you want on the Vserv Dashboard, each with a different category. If you already have a Vserv developer account and Default Zone ID you can skip this step.

Download Vserv Android SDK

Next, download download the Vserv Android SDK. Unzip the downloaded file, and you'll have a folder named as AndroidV2SDKLibrary/ which contains the Vserv Android SDK.

Integrate Vserv Android SDK Library

Now import the Vserv Android SDK library into your Project as follows:

  • Navigate to Project->Property->Android
  • Select the Vserve Android SDK library and add it into the Project.

Updating your project.properties

Now add the following code to your project.properties file.

manifestmerger.enabled=true

Update Vserv Library AndroidManifest

Now update the AndroidManifest.xml File in the Vserv Library. Delete the following code from the file.

<metadata
android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />

Provide Internet Access Permission

Your App will need internet access to fetch ads from the Vserv Ad Network. Therefore, you have to provide internet access permissions by adding the following code to the AndroidManifest.xml File. Add it outside the application tag.

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Request Vserv Ads

FInally you need to request ads from the Vserv Ad Network. The Vserv.mobi SDK provides you with various mechanisms to request ads from your Nokia X application.

Requesting Ads using displayAd()

displayAd() has three constructors that can be used to request Ads.

Managed Ads using displayAd()

First, create and initialize an instance VservManager(mobi.vserv.android.ads). Now request ads using the displayAd() of the VservManager object.

    VservManager manager = VservManager.getInstance(context);
manager.setShowAt(AdPosition.IN);
manager.displayAd(ZONE_ID);

YOUR_ZONE_ID is the Zone ID you received in the Welcome Email from Vserv.


Overlay Ads using displayAd()

By default, the DisplayAd() method displays an interstitial. However itcan be used to display an Overlay ad for a more native experience. To request an Overlay ad you need to pass AdType.OVERLAY to the Overloaded displayAd() method.

    VservManager manager = VservManager.getInstance(context);
manager.setShowAt(AdPosition.IN);
manager.displayAd(ZONE_ID, AdType.OVERLAY);

You can pass either AdType.OVERLAY & AdType.INTERSTITIAL to displayAd().

Orientation Ads in displayAd()

You can request for an interstitial in a particular orientation by passing an AdOrientation parameter to displayAd() as shown.

    VservManager manager = VservManager.getInstance(context);
manager.setShowAt(AdPosition.IN);
manager.displayAd(ZONE_ID, AdOrientation.LANDSCAPE);

Ad orientation will either be AdOrientation.LANDSCAPE or AdOrientation.PORTRAIT

Requesting Ads using getAd()

This mechanism gives you the maximum control over Ad retrieval. getAd() allows you to prefetch multiple ads. It takes in two parameters, a ZoneID and an AdLoadCallBack listener.

    getAd(ZONE_ID, AdLoadCallback myAdLoadCallbackListener)

You can also request a particular ad orientation with getAd() by passing an AdOrientation parameter.

    getAd(ZONE_ID, AdOrientation adOrientation, AdLoadCallback myAdLoadCallbackListener)

The AdLoadCallback (mobi.vserv.android.appwrapper.AdLoadCallback) interface provides callbacks to get the status of your request. It has the following callbacks:

    onLoadSuccess(VservAd adObj)

This callback method is invoked when an ad has been successfully retrieved.

    onLoadFailure()

This callback method is invoked when there is an error in retrieving the ad from the Vserv Ad Network.

    onNoFill()

This callback method is invoked when there is no ad available.

A sample implementation of the getAd() method with the callback is shown below. This sample used the overlay() method to show the interstitial immediately.

    final Context context=MainActivity.this;
VservManager manager = VservManager.getInstance(context);
manager.getAd("ZONE_ID", new AdLoadCallback() {
 
public void onLoadSuccess(VservAd adObj) {
adObj.overlay(context);
}
 
public void onLoadFailure() {
// code to execute on Failure of Ads loading
}
 
public void onNoFill() {
// Code when no ads are returned
}
 
});


Managed Banner Ads using renderAd()

You can request banner ads that automatically auto refresh in a specific view using renderAd(). The method signature is shown below:

    VservController renderAd(String zoneId, ViewGroup viewGroup)

The ViewGroup is a container in your activity layout where you want the ad to be displayed.

Summary

By following the above-mentioned steps, you can easily integrate Vserv Ads into Nokia X apps.

The source code of an app that implements Vserv Ads is attached. This app shows Vserv Ads upon app launch and close using the displayAd() method, and when a button click event fires using the getAd() method.

If you want to see implementation of this code, download Leap Year available in the Nokia Store.

For more information, you can also refer to the vserv.mobi Developer Wiki.

This page was last modified on 2 June 2014, at 23:49.
217 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×