I found a Flappy Bird GitHub project and changed it a little bit. I successfully implemented the AdMob Banner.
But now I also want a Interstitial Ad which pops up w
You already integrated banner Ad so no need to injected dependent artifact in your project.
Follow these steps for Interstitial Ad integration.
AndroidManifest.xml
Make an entry of AdActivity
for Interstitial Ad
Create an interface inside your core module
public interface AdService {
boolean isInterstitialLoaded();
void showInterstitial();
}
Create a parameterized constructor of FlappyGame
class
public AdService adService;
public FlappyGame(AdService ads){
adService=ads;
}
Implement AdService
interface to your AndroidLauncher
class
public class AndroidLauncher extends AndroidApplication implements AdService {
private static final String AD_UNIT_ID_INTERSTITIAL = "ca-app-pub-XXXXX/XXXXX";
private InterstitialAd interstitialAd;
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
View gameView=initializeForView(new FlappyGame(this), config);
...
interstitialAd = new InterstitialAd(this);
interstitialAd.setAdUnitId(AD_UNIT_ID_INTERSTITIAL);
interstitialAd.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {}
@Override
public void onAdClosed() {
loadIntersitialAd();
}
});
loadIntersitialAd();
}
private void loadIntersitialAd(){
AdRequest interstitialRequest = new AdRequest.Builder().build();
interstitialAd.loadAd(interstitialRequest);
}
@Override
public void showInterstitial() {
runOnUiThread(new Runnable() {
public void run() {
if (interstitialAd.isLoaded())
interstitialAd.show();
else
loadIntersitialAd();
}
});
}
@Override
public boolean isInterstitialLoaded() {
return interstitialAd.isLoaded();
}
}
GameScreen
class
RunnableAction playWooshAction = Actions.run(new Runnable() {
@Override
public void run() {
com.pentagames.flappybibi.Assets.playWooshSound();
game.adService.showInterstitial();
}
});
I integrated Interstitial Ad in your project, created a pull request for the same. You can merge my pull request.