×
Namespaces

Variants
Actions
(Difference between revisions)

Integrating Vserv Ads in Nokia X

From Nokia Developer Wiki
Jump to: navigation, search
pardeepsharma10 (Talk | contribs)
(Pardeepsharma10 -)
mfabiop (Talk | contribs)
(Mfabiop -)
Line 48: Line 48:
 
Next step would be to update project.properties file. add below code in the File
 
Next step would be to update project.properties file. add below code in the File
  
                   
+
<code>                   
manifestmerger.enabled=true
+
manifestmerger.enabled=true
 
+
</code>
  
 
===Update Vserv Library AndroidManifest ===
 
===Update Vserv Library AndroidManifest ===
 
Now update the AndroidManifest.xml File in the Vserv Library. Delete the following code from the File
 
Now update the AndroidManifest.xml File in the Vserv Library. Delete the following code from the File
  
 +
<code xml>
 
<metadata
 
<metadata
 
  android:name="com.google.android.gms.version"  android:value="@integer/google_play_services_version" />
 
  android:name="com.google.android.gms.version"  android:value="@integer/google_play_services_version" />
 
+
</code>
  
 
===Provide Internet Access Permission===
 
===Provide Internet Access Permission===
 
Your App will need internet to fetch Ads from Vserv Ad Network. So, you have to provide Internet access permission which can be done by following code in the AndroidManifest.xml File. add it outside application tag.
 
Your App will need internet to fetch Ads from Vserv Ad Network. So, you have to provide Internet access permission which can be done by following code in the AndroidManifest.xml File. add it outside application tag.
  
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
+
<code xml>
 
+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
 +
</code>
  
 
===Request Vserv Ads===
 
===Request Vserv Ads===
Line 70: Line 72:
  
 
====Requesting Ads using displayAd()====
 
====Requesting Ads using displayAd()====
displayAd() method have three constructor to request Ads.
+
{{Icode|displayAd()}} method have three constructor to request Ads.
  
  
Line 76: Line 78:
 
First create object of VservManager(mobi.vserv.android.ads) and initialize it. Now request ads using displayAd() of VservManager Object.
 
First create object of VservManager(mobi.vserv.android.ads) and initialize it. Now request ads using displayAd() of VservManager Object.
  
VservManager manager = VservManager.getInstance(context);
+
<code java>
manager.setShowAt(AdPosition.IN);
+
    VservManager manager = VservManager.getInstance(context);
manager.displayAd(ZONE_ID);
+
    manager.setShowAt(AdPosition.IN);
 +
    manager.displayAd(ZONE_ID);
 +
</code>
  
 
YOUR_ZONE_ID is Zone ID you received in the Welcome Email.  
 
YOUR_ZONE_ID is Zone ID you received in the Welcome Email.  
Line 84: Line 88:
  
 
=====Overlay Ads using displayAd()=====
 
=====Overlay Ads using displayAd()=====
The DisplayAd() method by default displays an interstitial but can be used to display an Overlay ad for a more native experience. To request an Overlay ad you need to pass the AdType to the Overloaded displayAd()
+
The {{Icode|DisplayAd()}} method by default displays an interstitial but can be used to display an Overlay ad for a more native experience. To request an Overlay ad you need to pass the AdType to the Overloaded {{Icode|displayAd()}} method.
method.
+
  
VservManager manager = VservManager.getInstance(context);
+
<code java>
manager.setShowAt(AdPosition.IN);
+
    VservManager manager = VservManager.getInstance(context);
manager.displayAd(ZONE_ID, AdType.OVERLAY);
+
    manager.setShowAt(AdPosition.IN);
 
+
    manager.displayAd(ZONE_ID, AdType.OVERLAY);
You can pass either AdType.OVERLAY & AdType.INTERSTITIAL to displayAd().
+
</code>
  
 +
You can pass either {{Icode|AdType.OVERLAY}} & {{Icode|AdType.INTERSTITIAL}} to {{Icode|displayAd()}}.
  
 
=====Orientation Ads in 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);
+
You can request for an interstitial in a particular orientation by passing an AdOrientation parameter to {{Icode|displayAd()}} as shown.
manager.setShowAt(AdPosition.IN);
+
 
manager.displayAd(ZONE_ID, AdOrientation.LANDSCAPE);
+
<code java>
 +
    VservManager manager = VservManager.getInstance(context);
 +
    manager.setShowAt(AdPosition.IN);
 +
    manager.displayAd(ZONE_ID, AdOrientation.LANDSCAPE);
 +
</code>
  
Ad orientation will either be AdOrientation.LANDSCAPE or AdOrientation.PORTRAIT
+
Ad orientation will either be {{Icode|AdOrientation.LANDSCAPE}} or {{Icode|AdOrientation.PORTRAIT}}
  
  
 
====Requesting Ads using getAd()====
 
====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)
+
This mechanism gives you the maximum control over Ad retrieval. {{Icode|getAd()}} allows you to prefetch multiple Ads. It takes in two parameters, a ZoneID and an AdLoadCallBack listener.
 +
 
 +
<code java>
 +
    getAd(ZONE_ID, AdLoadCallback myAdLoadCallbackListener)
 +
</code>
  
 
In addition you can also request for a particular orientation by passing an AdOrientation parameter.
 
In addition you can also request for a particular orientation by passing an AdOrientation parameter.
  
getAd(ZONE_ID, AdOrientation adOrientation, AdLoadCallback myAdLoadCallbackListener)
+
<code java>
 +
    getAd(ZONE_ID, AdOrientation adOrientation, AdLoadCallback myAdLoadCallbackListener)
 +
</code>
  
The AdLoadCallback (mobi.vserv.android.appwrapper.AdLoadCallback) interface provides callsbacks to get the status of you’re a Request. It has the following callbacks:
+
The {{Icode|AdLoadCallback}} (mobi.vserv.android.appwrapper.AdLoadCallback) interface provides callsbacks to get the status of you’re a Request. It has the following callbacks:
  
onLoadSuccess(VservAd adObj) :
+
<code java>
 +
    onLoadSuccess(VservAd adObj)
 +
</code>
 
This callback method is invoked when an Ad has been successfully retrieved.  
 
This callback method is invoked when an Ad has been successfully retrieved.  
  
onLoadFailure()
+
<code java>
This callback method is invoked when there was an error in retrieving the Ad from the Vserv Ad Network
+
    onLoadFailure()
 +
</code>
 +
This callback method is invoked when there was an error in retrieving the Ad from the Vserv Ad Network.
  
onNoFill()
+
<code java>
 +
    onNoFill()
 +
</code>
 
This callback method is invoked when there was no Ad available.
 
This callback method is invoked when there was 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.
+
A sample implementation of the getAd() method with the callback is shown below. This sample used the {{Icode|overlay()}} method to show the interstitial immediately.
  
                final Context context=MainActivity.this;
+
<code java>
    VservManager manager = VservManager.getInstance(context);
+
    final Context context=MainActivity.this;
    manager.getAd("ZONE_ID", new AdLoadCallback() {
+
    VservManager manager = VservManager.getInstance(context);
    public void onLoadSuccess(VservAd adObj) {
+
    manager.getAd("ZONE_ID", new AdLoadCallback() {
   
+
   
    adObj.overlay(context);
+
        public void onLoadSuccess(VservAd adObj) {
    }
+
            adObj.overlay(context);
    public void onLoadFailure() {
+
        }
      // code to execute on Failure of Ads loading
+
   
    }
+
        public void onLoadFailure() {
    public void onNoFill() {
+
            // code to execute on Failure of Ads loading
      // Code when no ads are returned
+
        }
    }
+
   
    });
+
        public void onNoFill() {
 
+
            // Code when no ads are returned
 +
        }
 +
   
 +
    });
 +
</code> 
  
  
 
====Managed Banner Ads using renderAd()====
 
====Managed Banner Ads using renderAd()====
You can request for Banner Ads which auto refresh automatically in a specific View using renderAd(). The signature for the method is shown below:
+
You can request for Banner Ads which auto refresh automatically in a specific View using {{Icode|renderAd()}}. The signature for the method is shown below:
  
VservController renderAd(String zoneId, ViewGroup viewGroup)
+
<code java>
 +
    VservController renderAd(String zoneId, ViewGroup viewGroup)
 +
</code>
  
 
The ViewGroup is a container in your Activity layout where you want the Ad to be displayed.
 
The ViewGroup is a container in your Activity layout where you want the Ad to be displayed.
 
 
  
 
== Summary ==
 
== Summary ==
Following above mentioned steps would help you easily integrate Vserv Ads into NOKIA X Apps. Developers can also earn some Reward points in DVLUP- NOKIA Reward Program by participating in Challenges. Source Code of App implementing Vserv Ads is Attached. App shows Vserv Ads on App Lunching, Closing using displayAd()method and on the click on Button using the getAd() method.   
+
Following above mentioned steps would help you easily integrate Vserv Ads into NOKIA X Apps. Developers can also earn some Reward points in DVLUP- NOKIA Reward Program by participating in Challenges. Source Code of App implementing Vserv Ads is Attached. App shows Vserv Ads on App Lunching, Closing using {{Icode|displayAd()}} method and on the click on Button using the {{Icode|getAd()}} method.   
  
 
Feel free to edit this Article.
 
Feel free to edit this Article.

Revision as of 18:36, 15 April 2014

This article explains step by step integration of Vserv Ads into NOKIA X App using Vserv Android SDK

Note.pngNote: This is an 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 (15 Apr 2014)
Last edited: mfabiop (15 Apr 2014)


Contents

Introduction

Vserv Ad Network provide Advertisement support to almost all the Mobile Platform including 'NOKIA X'-the newest addition to the NOKIA family.I will use Vserv Android SDK for integration. this can be performed in number of steps described below.


Implementation

Register as Developer

First thing needed is a Developer Account.If you don't have one, register on the 'http://www.vserv.mobi' as Developer, your Default Zone ID would be sent to you in your welcome Email. I will use Default Zone ID in the sample, but you can create as many Zone ID as you want on Vserv Dashboard having different Categories. If you already have Developer account and Default Zone ID skip this Step.


Download Vserv Android SDK

Next step would be to Download Vserv Android SDK, you can download it here[[1]]. Unzip the Downloaded File. there would be a Folder named as AndroidV2SDKLibrary/ which contain Vserv Android SDK.


Integrate Vserv Android SDK Library

Now import Vserv Android SDK library in the Project. Next step would be add library into the Project. Go to Project->Property->Android and select the Library and ad it into the Project.


Updating your project.properties

Next step would be to update project.properties file. add below code in the 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 to fetch Ads from Vserv Ad Network. So, you have to provide Internet access permission which can be done by following code in the AndroidManifest.xml File. add it outside application tag.

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

Request Vserv Ads

Only thing now left to request Ads from Vserv Ad Network.The Vserv.mobi SDK provides you with various mechanisms to request for Ads in your Android application.


Requesting Ads using displayAd()

displayAd() method have three constructor to request Ads.


Managed Ads using displayAd()

First create object of VservManager(mobi.vserv.android.ads) and initialize it. Now request ads using displayAd() of VservManager Object.

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

YOUR_ZONE_ID is Zone ID you received in the Welcome Email.


Overlay Ads using displayAd()

The DisplayAd() method by default displays an interstitial but can be used to display an Overlay ad for a more native experience. To request an Overlay ad you need to pass the AdType 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)

In addition you can also request for a particular orientation by passing an AdOrientation parameter.

    getAd(ZONE_ID, AdOrientation adOrientation, AdLoadCallback myAdLoadCallbackListener)

The AdLoadCallback (mobi.vserv.android.appwrapper.AdLoadCallback) interface provides callsbacks to get the status of you’re a 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 was an error in retrieving the Ad from the Vserv Ad Network.

    onNoFill()

This callback method is invoked when there was 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 for Banner Ads which auto refresh automatically in a specific View using renderAd(). The signature for the method 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

Following above mentioned steps would help you easily integrate Vserv Ads into NOKIA X Apps. Developers can also earn some Reward points in DVLUP- NOKIA Reward Program by participating in Challenges. Source Code of App implementing Vserv Ads is Attached. App shows Vserv Ads on App Lunching, Closing using displayAd() method and on the click on Button using the getAd() method.

Feel free to edit this Article.

226 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.

×