Back to project page game_guess_lib.
The source code is released under:
MIT License
If you think the Android project game_guess_lib listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.wkmf.guess.lib.common.ads; // w w w.ja v a2 s . c o m import android.content.Context; import com.google.android.gms.ads.AdListener; import com.google.android.gms.ads.AdRequest; import com.google.android.gms.ads.InterstitialAd; /** * Created by ernestofndz on 26/02/14. */ public class GuessGameAds { private final String AD_UNIT = "ca-app-pub-5969111340003579/1156414846"; private InterstitialAd interstitialAd; private boolean adLoaded = false; // inicializamos el ad public void initAd(Context context, final GuessGameAdsListener adsListener) { this.interstitialAd = new InterstitialAd(context); this.interstitialAd.setAdUnitId(AD_UNIT); final AdRequest.Builder adRequestBuilder = new AdRequest.Builder(); adRequestBuilder.addTestDevice(AdRequest.DEVICE_ID_EMULATOR); // aadimos un listener this.interstitialAd.setAdListener(new AdListener() { @Override public void onAdLoaded() { adLoaded = true; } @Override public void onAdClosed() { // marcamos como que no est cargado adLoaded = false; // hacemos la peticin de vuelta adsListener.onAdClosed(); } }); // cargamos el ad this.interstitialAd.loadAd(adRequestBuilder.build()); } // comprobar que se carg el ad public boolean isAdLoaded(){ return this.adLoaded; } // mostrar el ad public void showAd(){ if(isAdLoaded()){ this.interstitialAd.show(); } } }