Sonar cocos helper admob full add problem

Hello

Can I on JS preload in Admob full add and display it when I will need it?

Perhaps you should ask this on their forums as well, There might be a larger audience there for Cocos Helper, although @SonarSystems does participate here as well. http://www.sonarlearning.co.uk/questions.php

Are you talking about a particular method for pre loading or auto preloading?

Either of them, I have the problem that I’m showing ads on game over, but user is able to start another game and ad is displayed than when he plays. So I think it’s not auto preloaded. I don’t see any preload function on JS side also…

There is no preload method, what is the exact game flow in terms of seconds switching and events occurring.

can you do a preload of interstitial? it will help much.

any info about that? I can use it without preload, it can’t be shown when users play… sometimes before it load user already is restarting game…

Let us ask @SonarSystems for an update.

No preload feature yet but more updates are coming.

when that feature will be available? or at least some callback when ad is displayed… than I can do some workaround…

We don’t have any ETA ATM sorry.

Hey @Likon I actually have a workaround for this (for android). I am not sure if you still need this, or you have found another workaround but… It’s really annoying especially on Android.

So what I did is;

  1. When you first time load the game, call this;

    var o = jsb.reflection.callStaticMethod(“sonar/systems/framework/SonarFrameworkFunctions”, “PreLoadFullscreenAdAM”, “()V”);

This will preload the ad.

  1. Then wherever you are calling showFullscreenAd(); method, use this instead;

    var o = jsb.reflection.callStaticMethod(“sonar/systems/framework/SonarFrameworkFunctions”, “ShowPreLoadedFullscreenAdAM”, “()V”);

This will show the preloaded ad.

  1. But we are not done yet. We have to change the “AdMobAds.java” file a bit :smile: . (You can find it here -> YourProject/frameworks/runtime-src/proj.android-studio/app/src/sonar/systems/frameworks/AdMob/AdMobAds.java)

So there is a listener, which triggers the ad to show up when it’s preloaded. We don’t want that now, So comment public void onAdLoaded() method out. We also need to know, when the user closes the ad, so we can prepare a new ad at the background.

So what I did is; I created a private method named createInterstitial() and moved the
interstitial = new InterstitialAd(activity); interstitial.setAdUnitId(interstitial_id); ......
in it. You can call this method on onCreate()

private void createInterstitial() {
    // Create the interstitial.
    interstitial = new InterstitialAd(activity);
    interstitial.setAdUnitId(interstitial_id);
   
    interstitial.setAdListener(new AdListener() {
        /* We don't want to do anything when the ad arrives :) 
         public void onAdLoaded()
         {
         if(preLoadCalled)
         {
        		  FullscreenAdPreloaded(true);
         }
         else
         {
        		  LoadFullscreenAd();
         }
         
         preLoadCalled = false;
         
         }
         */
        
        // User closed the previous ad, so bring me a new one!
        public void onAdClosed() {
            preLoadCalled = false;
            createInterstitial();
            PreLoadFullscreenAd();
        }
        
    }); 

}

So whenever user closes the ad, it will load the new one.

It works for me on android, but I am not actually sure if it’s the best or the cleanest way…
(I recommend you to backup your code first…)

Thanks for the full work around. I did manage to do it earlier. Was quite easy. Sonar didnt even bother spend 10 min on it. But now I’ve changed to sdkbox admob.

Cheers!

@Likon At first I was going to use SKDBox, but I had some difficulties with analytics on android with SDKBox. So I that’s why I am currently using Sonar Cocos Helper. Okay so I am glad to hear that you solved it :smile:

You must use theirs google play services. Just import it as a plugin :blush:

@aleksmutlu I just want to tell you that cocos helper have Google analytics and Flurry Analytics :smiley:

@OscarLeif Yeah I know that :slight_smile: I’m actually using Google Analytics on my game. It works great :smile: I had some difficulties with SDKBox, so I switched it to Cocos Helper :smile:

1 Like

AWESOME :smiley:

Im having a weird issue with the AdMob ads. When the game starts, the ads are shown, thats fine. If I move to a new scene with Director::getInstance()->replaceScene(); The new scene loads, the ads are there, all is fine.

But on Google Analytics it shows that the active screen is

com.google.android.gms.ads.AdActivity

even though I have set the screen name using

SonarCocosHelper::GoogleAnalytics::setScreenName("Game Scene");

The problem occurs when I press the home button on my Galaxy S4. The app moves to the background, then when it is opened again the banner ads are gone. If I then use the Quit button which calls Director::getInstance()->end(); the screen goes black but the game just reloads, and the ads are displayed again. Its like there is a layer being created over the game showing the ads that is closed when I first hit Quit.

Im putting it down to the com.google.android.gms.ads.AdActivity created for displaying the ads.

How do I get the banner ads to be displayed after the app is resumed from being in the background? Or close the com.google.android.gms.ads.AdActivity view when the game is put in the background and then create it again on resume?