Manifest Permission
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.InterstitialAd;
...
...
InterstitialAd mInterstitialAd;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("ca-app-pub-264***********");
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.build();
mInterstitialAd.loadAd(adRequest);
// Prepare an Interstitial Ad Listener
mInterstitialAd.setAdListener(new AdListener() {
public void onAdLoaded() {
// Call displayInterstitial() function
displayInterstitial();
}
});
...
...
...
public void displayInterstitial() {
// If Ads are loaded, show Interstitial else show nothing.
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
}
}
Hello everyone E/dalvikvm(27771): Could not find class 'android.app.AppOpsManager', referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zza
E/dalvikvm(27771): Could not find class 'android.app.AppOpsManager', referenced from method com.google.android.gms.common.kf.a
LogCat show this error.. Program run but it doesn't show ads.
To show an interstitial ad you need to ad an extra "activity" to your manifest, for example:
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
If this don't work, try adding
android:multiprocess="true" //or maybe
android:process=":remote"
AdMob interstitials are full-page ads that appear in your app at natural breaks or transition points. A common use case is after a level is completed in a game.