-
-
Save codingwithsara/b6f1df26962e0bb50a98134ec8132b5a to your computer and use it in GitHub Desktop.
Catch the Ball – #11 Implement AdMob Interstitial Ad
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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