How To Become A Programmer Without A Degree & Experience

Catch the Ball – #11 Implement AdMob Interstitial Ad

[Game1] Android Studio Game Tutorial – #11(Final) Implement AdMob Interstitial Ad

[Game1] Android Studio Game Tutorial - #11(Final) Implement AdMob Interstitial Ad

 

 

Introduction

Are you enjoying “Catch the Ball” development?

This is the final video of this series, and it might be the most important part for you…
Implementing ads!

In the video, I’ll show you how to implement AdMob interstitial ads.
Please remember that you need to log into your AdMob account and get unit ID when you release the app.

Good luck 🙂

 
 

Sample Code

<!-- Include required permissions for Google Mobile Ads to run-->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
 
 
<!--This meta-data tag is required to use Google Play Services.-->
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
 
 
<!--Include the AdActivity configChanges and theme. -->
<activity android:name="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" android:theme="@android:style/Theme.Translucent" />
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();
        }
 
    }
 
}