Skip to content

Instantly share code, notes, and snippets.

@codingwithsara
Created November 9, 2018 05:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codingwithsara/b6f1df26962e0bb50a98134ec8132b5a to your computer and use it in GitHub Desktop.
Save codingwithsara/b6f1df26962e0bb50a98134ec8132b5a to your computer and use it in GitHub Desktop.
Catch the Ball – #11 Implement AdMob Interstitial Ad
package codingwithsara.com.catchtheball;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.InterstitialAd;
public class start extends AppCompatActivity {
private InterstitialAd interstitial;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_start);
// Create the interstitial.
interstitial = new InterstitialAd(this);
// Set your unit id. THIS IS TEST ID!!
interstitial.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
// Create request.
AdRequest adRequest = new AdRequest.Builder().build();
// Start loading...
interstitial.loadAd(adRequest);
// Once request is loaded, display ad.
interstitial.setAdListener(new AdListener() {
public void onAdLoaded() {
displayInterstitial();
}
});
}
public void displayInterstitial() {
if (interstitial.isLoaded()) {
interstitial.show();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment