Adwhirl Custom Integration
AdWhirl is an open source tool for developers to help them serve advertisment from multiple advertising networks. You can learn more about AdWhirl at by visiting the AdWhirl website
This article describes how you can use Adfonic's SDKs if you are using AdWhirl in your application. It assumes that you are already familiar with how AdWhirl works.
Contents |
Getting Started
To get live ads in your app you just need to:
- Download the SDK and follow the integration steps below
- Sign up for an account on the main Adfonic site
- Add your app to your Adfonic account by going to the Add site or app page
- You can now get your Ad Slot ID from the Ad Integration page and replace the test id in your code - it looks like 22222222-2222-2222-2222-222222222222
Using AdWhirl with Adfonic in iOS
To use views provided by Adfonic SDK in AdWhirl, first you need to add both of the libraries to your project. See Installing Adfonic SDK for iOS and AdWhirl's website.
You will need to add a custom event to support Adfonic. To do this, visit the Ad Network Settings page of your app on Adwhirl’s website. Click on the “Add Custom Events” button. Enter any name you like, for example Adfonic. You should alse enter the name of the method AdWhirl should call, for example showAdfonicBanner:. After creating the event, you can now turn it on and configure it like any other ad network.
Now you should implement the custom method you specified above in your AdWhirl delegate. You can create an Adfonic banner and pass it back to AdWhirl to display it. This is a sample implementation of this method:
- (void)showAdfonicBanner:(id)adWhirlView {
if ( adfBannerView == nil ) {
// Initialize the banner view
adfBannerView = [ADFBannerView bannerViewWithType:nil];
// Do not auto-refresh, AdWhirl takes care of the refresh
adfBannerView.bannerViewAutorefreshTime = 0;
// Uncomment if your class implements the ADFBannerViewDelegate protocol
// adfBannerView.delegate = self;
} else {
[adfBannerView refresh];
}
// Give AdWhirl visibility of the banner
[adWhirlView replaceBannerViewWith:adfBannerView];
}
AdWhirl will automatically call this method based on the traffic percentage you have assigned to Adfonic and manages the displaying of the banner.
Using AdWhirl with Adfonic in Android
Please visit AdWhirl's Wiki page and read the information provided.
1. Download the Android SDK
2. Add the adfonic_android.jar and AdWhirlSDK_Android_3.0.0.jar files to your project library
3. Add the following to your AndroidManifest.xml.
<activity android:name="AdwhirlIntegration" android:configChanges="orientation" android:label="Adwhirl Integration"> <meta-data android:value="8ebb402972284c059c3c29290c148c1f" android:name="ADWHIRL_KEY"/> </activity>
4. Replace 8ebb402972284c059c3c29290c148c1f with your Adwhirl SDK Key from Adwhirl's website.
5. Within AdWhirl's website click "Add Custom Event", using the function name "requestAds". Make sure custom event is "ON" then click "Save Changes".
6. Add the view to your project "adwhirl_integration_layout.xml"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.sample.android.example"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="0px"
android:layout_weight="1.0"
android:text="@string/adwhirl_ad_desc"
style="@style/Text.HomeMsg"
/>
<com.adwhirl.AdWhirlLayout
android:id="@+id/adwhirl_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FFFFFFFF"
/>
</LinearLayout>
6. Replace your package name where the namespace references "com.sample.android.example"".
7. You will need a new class called AdwhirlIntegration.java
package com.sample.android.example;
import java.util.HashMap;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import com.adfonic.android.AdfonicAdListener;
import com.adfonic.android.AdfonicAdView;
import com.adwhirl.AdWhirlLayout;
import com.adwhirl.AdWhirlLayout.AdWhirlInterface;
import com.adwhirl.AdWhirlManager;
import com.adwhirl.AdWhirlTargeting;
public class AdwhirlIntegration extends Activity implements AdfonicAdListener ,AdWhirlInterface {
private static final String TAG = "AdwhirlIntegration";
AdWhirlLayout adWhirlLayout;
HashMap<String, String> mapAdfonicValues;
AdfonicAdView adview;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.adwhirl_integration_layout);
mapAdfonicValues = new HashMap<String, String>();
mapAdfonicValues.put(AdfonicAdView.MAP_KEY_SLOT_ID, "22222222-2222-2222-2222-222222222222");
mapAdfonicValues.put(AdfonicAdView.MAP_KEY_SHOW_PROGRESS, "false");
mapAdfonicValues.put(AdfonicAdView.MAP_KEY_PROGRESS_TITLE, "Please wait");
mapAdfonicValues.put(AdfonicAdView.MAP_KEY_PROGRESS_TEXT, "Loading...");
mapAdfonicValues.put(AdfonicAdView.MAP_KEY_LOADING_TEXT, "Loading...");
mapAdfonicValues.put(AdfonicAdView.MAP_KEY_BACKGROUND_COLOUR, "#000000");//black
mapAdfonicValues.put(AdfonicAdView.MAP_KEY_TEXT_COLOUR, "#FFFFFF"); //white
mapAdfonicValues.put(AdfonicAdView.MAP_KEY_AD_TEXT, "Ad: ");
mapAdfonicValues.put(AdfonicAdView.MAP_KEY_TEST_MODE, "true");
mapAdfonicValues.put(AdfonicAdView.MAP_KEY_REFRESH_AD, "true"); //
mapAdfonicValues.put(AdfonicAdView.MAP_KEY_REFRESH_TIME, "20000");//every 20 secs
mapAdfonicValues.put(AdfonicAdView.MAP_KEY_AD_WIDTH, "300");
mapAdfonicValues.put(AdfonicAdView.MAP_KEY_AD_HEIGHT, "50");
mapAdfonicValues.put(AdfonicAdView.MAP_KEY_LANGUAGE, "en");
adview = new AdfonicAdView(this, mapAdfonicValues); //initialize
adview.setAdfonicAdListener(this); //optional
AdWhirlManager.setConfigExpireTimeout(1000 * 60 * 5);
AdWhirlTargeting.setAge(23);
AdWhirlTargeting.setGender(AdWhirlTargeting.Gender.MALE);
AdWhirlTargeting.setKeywords("online games gaming");
AdWhirlTargeting.setPostalCode("94123");
AdWhirlTargeting.setTestMode(false);
adWhirlLayout = (AdWhirlLayout)findViewById(R.id.adwhirl_layout);
adWhirlLayout.setAdWhirlInterface(this);
}
@Override
public void AdfonicAdFailed() {
Log.i(TAG, "Adfonic Ad failed");
}
@Override
public void AdfonicAdReturned() {
Log.i(TAG, "Adfonic Ad returned");
}
/**
* requestAds
* To be called from adwhirl website by custom events
*
*/
public void requestAds()
{
adWhirlLayout.addView(adview);
}
@Override
public void adWhirlGeneric() {
}
}
8. Make sure you use your unique "AdfonicAdView.MAP_KEY_SLOT_ID" - this is your Ad Slot ID
9. When the activity is called the layout will be built on the fly.
Intent adWhirlIntent = new Intent(); adWhirlIntent.setClass(getApplicationContext(), AdwhirlIntegration.class); startActivity(adWhirlIntent);