Question

I'm using Kii Cloud mobile backend as a service (MBaaS) on an Android application and I just added the SDK to use ad networks. I'm looking for a code snippet that shows how to display ads from several ad networks at the same time. Can anybody contribute that? Thanks.

Was it helpful?

Solution

First of all make sure that you have set up the ad networks that you want to work with on the developer console as described here. Then try adding the Kii ad layout to your screen layout like this:

// get scaledDensity 
Display display = getWindowManager().getDefaultDisplay(); 
DisplayMetrics metrics = new DisplayMetrics(); 
display.getMetrics(metrics); 
float scaledDensity = metrics.scaledDensity;  
// set targeting parameter 
KiiAdNetTargeting.setGender(KiiAdNetTargeting.Gender.FEMALE);
KiiAdNetTargeting.setKeywords("Application"); 
KiiAdNetTargeting.setAge(35); 
KiiAdNetTargeting.setPostalCode("30900");  
// create an KiiAdnetLayout 
KiiAdNetLayout adLayout = new KiiAdNetLayout(this, APP_ID, APP_KEY, KiiAdNetLayout.SiteID.US); 
layout.addView(adLayout); 
adLayout.setMaxWidth((int)(scaledDensity * 320)); 
adLayout.setMaxHeight((int)(scaledDensity * 52));

where "layout" is your top level Android layout where you want to embed the ad box. And of course the targeting parameters are just examples on how you can limit the audience.

By adding this Kii ad box you're already displaying all the ad networks that you configured on the developer console at the same time according to the percentages of display time that you defined for each.

*Important: you need to replace APP_ID and APP_KEY with your real app values*

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top