Skip to content

Instantly share code, notes, and snippets.

@codingwithsara

codingwithsara/start.java Secret

Created Nov 9, 2018
Embed
What would you like to do?
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