Admob Interstitial Alway Returns False

admob interstitial ad is never ready

Create a new swift file AdMobDelegate :-

import UIKit
import GoogleMobileAds

class AdMobDelegate: NSObject, GADInterstitialDelegate {

var interstitialView: GADInterstitial!

func createAd() -> GADInterstitial {
interstitialView = GADInterstitial(adUnitID: "Your Key")
interstitialView.delegate = self
let request = GADRequest()
interstitialView.loadRequest(request)
return interstitialView
}

func showAd() {
if interstitialView != nil {
if (interstitialView.isReady == true){
interstitialView.present(fromRootViewController:currentVc)
} else {
print("ad wasn't ready")
interstitialView = createAd()
}
} else {
print("ad wasn't ready")
interstitialView = createAd()
}
}

func interstitialDidReceiveAd(ad: GADInterstitial!) {
print("Ad Received")
if ad.isReady {
interstitialView.present(fromRootViewController: currentVc)
}
}

func interstitialDidDismissScreen(ad: GADInterstitial!) {
print("Did Dismiss Screen")
}

func interstitialWillDismissScreen(ad: GADInterstitial!) {
print("Will Dismiss Screen")
}

func interstitialWillPresentScreen(ad: GADInterstitial!) {
print("Will present screen")
}

func interstitialWillLeaveApplication(ad: GADInterstitial!) {
print("Will leave application")
}

func interstitialDidFailToPresentScreen(ad: GADInterstitial!) {
print("Failed to present screen")
}

func interstitial(ad: GADInterstitial!, didFailToReceiveAdWithError error: GADRequestError!) {
print("\(ad) did fail to receive ad with error \(error)")
}
}

Now you can use the object of this delegate class in other files as follows :-

//Define admobdelegate as global variable
var admobDelegate = AdMobDelegate()

//Declare a global variable currentVc to hold reference to current view controller
var currentVc: UIViewController!

class abc1: UIViewController {

override func viewdidload() {
super.viewdidload()
currentVc = self
admobDelegate.showAd()
}

override func viewDidAppear() {
super.viewDidAppear()
currentVc = self
}
}

class abc2: UIViewController {

override func viewdidload() {
super.viewdidload()
currentVc = self
admobDelegate.showAd()
}

override func viewDidAppear() {
super.viewDidAppear()
currentVc = self
}
}

Code is in Swift 2.2. Write your equivalent code in swift 3 in case of syntax error.

Admob interstitial stopped working without project changes

Add the latest gradle

compile 'com.google.android.gms:play-services-ads:9.2.1'  

and remove

dependencies {
...
classpath 'com.google.gms:google-services:3.0.0'
}

also remove plugin

apply plugin: 'com.google.gms.google-services'

Update:

I think you are missing AdRequest ?

   InterstitialAd mInterstitialAd = new InterstitialAd(mContext);
AdRequest adRequest = new AdRequest.Builder().build();

mInterstitialAd.setAdUnitId(mContext.getString(R.string.full_screen_id));
mInterstitialAd.loadAd(adRequest);

AdMob Interstitial Ad never becoming ready

For those reading this at a later time I fixed it, there were two problems:

I'm not using an actualy Ad, so request.testDevices should not be set to anything

Additionally, when I call GameViewController().displayAd(), I'm making a new instance of GameViewController, and it has to be the original. To avoid this I made a variable that referenced GameViewController's self, then did
variable.displayAd()

android InterstitialAd always not showing properly

I have reproduced this issue with 100% reproducibility. Look for workaround below.

Description:

Admob interstitial is shown incorrectly on Android

Steps to reproduce:

  1. Download admob interstitial sample using link "Download the example project" on page: https://developers.google.com/mobile-ads-sdk/docs/admob/advanced
  2. Open InterstitialSample.java
  3. Find in onCreate method the following 2 lines of code:

    interstitialAd = new InterstitialAd(this, AD_UNIT_ID_GOES_HERE);

    interstitialAd.setAdListener(this);

  4. Remove these 2 lines from onCreate method and add them to onClick before interstitialAd.loadAd(adRequest);
  5. Replace AD_UNIT_ID_GOES_HERE by your id
  6. Add GoogleAdMobAdsSdk-6.3.0.jar to project
  7. Build and run
  8. Click "Load Interstitial" button then "Show Interstitial" button
Observed result:

When device is in portrait orientation an interstitial shows landscape version of ad content, and vice versa when device is in landscape orientation an interstitial shows portrait version of ad content.

Configuration used for testing:

Android OS: 4.2.1 or 4.2.2

GoogleAdMobAdsSdk: 6.2.1 or 6.3.0

Device: Galaxy Nexus

Workaround:

As you can see original sample without modification (when creation of InterstitialAd is done in Activity.onCreate) works properly. So main idea for workaround is to create the same conditions for showing interstitial inside your real application. If you couldn't place code for creating InterstitialAd object inside onCreate method of your real Activity or you need to show interstitial from arbitrary code (for example form inside library code) then you need to create additional "launcher" Activity.

In my case I have used the following steps:

1. Create additional Activity (based on InterstitialSample from Google sample) which will be used as launcher for interstitial ad

2. Add code for creating InterstitialAd object and setting listener inside onCreate method of that Activity

3. Add code for loading interstitial ad to onCreate method

4. Add code for displaying interstitial ad to onReceiveAd listener method

5. Add code for finishing Activity to onFailedToReceiveAd and onDismissScreen listener methods

Then just launch this additional "launcher" Activity whenever you need to show ad. This workaround works for me.

Admob Interstitial Ad fails to load

I use this ads in my application and working correctly.

Have a look at below example.

InterstitialAd mInterstitialAd;
Button mNewGameButton;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.google_ad_mob);

mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId(<your ad unit id goes here>);
final AdRequest.Builder adRequestBuilder = new AdRequest.Builder();
adRequestBuilder.addTestDevice("your test device id goes here");
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
super.onAdLoaded();
}
@Override
public void onAdClosed() {
super.onAdClosed();
mInterstitialAd.loadAd(adRequestBuilder.build());
}
});
mInterstitialAd.loadAd(adRequestBuilder.build());

mNewGameButton = (Button) findViewById(R.id.newgame_button);

newgame_button.setOnClickListener(this);

}

@Override
public void onClick(View v) {
Intent intent;
switch (v.getId()) {

case R.id.newgame_button:
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
}
break;
}
}

@Override
protected void onResume() {
super.onResume();
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
}
}

Admob Interstitial Ad not loading in Fragment in Android

From your code, you show the interstitial ad right after loading it.

There's always a latency(delay) issue with ads getting shown after requesting/loading them.

So you can't display your ad if it isn't loaded yet. Ideally, you should show interstitial ads at a natural break point in your app. Example: when transitioning from one activity to the other. However, you can modify your code to display the ad via the #onAdLoaded in your #onCreateView like this:

        @Override
public void onAdLoaded() {
super.onAdLoaded();
mInterstitialAd.show();
}


Related Topics



Leave a reply



Submit