AdMob Mediation

From Adfonic Wiki
Jump to: navigation, search

Contents

Introduction

This page assumes you have already downloaded the Android or iOS SDKs.

Read more on the features and benefits of Adfonic with AdMob Mediation.

Android

1. Android Banners - create a new Google AdView using your mediation id from the AdMob website.

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.banner);
        FrameLayout container = ((FrameLayout) findViewById(R.id.content));
        com.google.ads.AdView adView = new AdView(this, AdSize.BANNER, "XXXXXXXXXXXXXXXX"); // 300x50
        adView.loadAd(new AdRequest());
        adView.setVisibility(View.VISIBLE);
        container.addView(adView);
    }

2. Android Interstitial (Full Page) -- create a new Google InterstitialAd using your mediation id from the AdMob website.

    private InterstitialAd interstitial;
    private Button showInterstitial;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.interstitial);
        showInterstitial = (Button) findViewById(R.id.showinterstitial);
        interstitial = new InterstitialAd(this, "XXXXXXXXXXXXXXXX");
        interstitial.setAdListener((com.google.ads.AdListener) this);
        interstitial.loadAd(new AdRequest());
        showInterstitial.setVisibility(View.VISIBLE);
        showInterstitial.setEnabled(false);
    }
   
    @Override
    public void onReceiveAd(Ad ad) {
        Log.v("onReceiveAd");

        if (ad == interstitial && interstitial.isReady()) {

            showInterstitial.setEnabled(true);
            showInterstitial.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    interstitial.show();
                    showInterstitial.setVisibility(View.GONE);
                }
            });
        }
    }

iOS

To include AdMob mediation for iOS in you app:

1. Add the libAdapterSDKAdfonic.a library to your project and ensure it is listed in the target's Link Binaries Build Phase. 2. Add the following additional frameworks to your target's Link Binaries Build Phase :


3. Add ORMMA.bundle to your project's resources.

4. To add display a banner using AdMob mediation for iOS, create a new GADBannerView, using the your mediation id as the adUnitID:


    GADBannerView * bannerView = [[[GADBannerView alloc] initWithAdSize: kGADAdSizeBanner] autorelease];
    bannerView.rootViewController = self;
    bannerView.adUnitID = @"<mediation-id>";
    bannerView.delegate = self;
    bannerView.hidden = YES;

    [self.view addSubview: bannerView];

    [bannerView loadRequest: self.request];

Implement the delegate method to display the ad:


- (void)adView:(GADBannerView *)view didFailToReceiveAdWithError:(GADRequestError *)error
{
    view.hidden = NO;
}


5. To add display an interstitial (full page) ad using AdMob mediation for iOS, create a new GADInterstitial, using the your mediation id as the adUnitID:

   GADInterstitial * interstitial = [[[GADInterstitial alloc] init] autorelease];
   interstitial.adUnitID = @"<mediation-id>";
   interstitial.delegate = self;
   [interstitial loadRequest: self.request];

implement the delegate method to display the ad:

- (void)interstitialDidReceiveAd:(GADInterstitial *)ad 
{
    [ad presentFromRootViewController: self];
}
Personal tools
Namespaces
Variants
Actions
App/Site Integration
Ad Campaign Tracking
Adfonic API
Troubleshooting
Toolbox