Home Features Docs Blog Support GitHub

AdMob and LibGDX Demo Project


(David Wernhart) #1

Dear MOE Community

In the past days, I have been trying to get a MOE project with LibGDX working that uses the Google Admob SDK with bindings.
Since there was no straightup tutorial and helpful documentation (I suspect that this gets fixed with the MOE 2.0 release), I got my information from various GitHub pages and forum entrys.

Some links that helped me:

In the end, I got a working demo project (you have to tap on the screen to show/hide the ad).
MOE Version 1.3.6, LibGDX Version 1.9.6

Feel free to use my code!

Best regards,

David Wernhart


(Gergely Kis - Migeran) #2

Dear @wernimaster,

thank you for the example app to use AdMob with LibGDX.

Best Regards,
Gergely


(Herman Tse) #3

Hi David,

I’ve tried to adopt your above admobtest code on my environment and finally get it running on my device without any error but no banner ads was shown. I can only see the badlogic logo displayed with the red background.

My environment:
Mac OS 10.11.6
Android Studio 3.0
Xcode 7.3.1
com.android.tools.build:gradle:3.0.0
org.multi-os-engine:moe-gradle:1.3.6
gdxVersion = ‘1.9.7’

I would like to share my code but I’m new to GitHub and still struggling how to upload folders of codes or create folder on GitHub manually. At the moment, I’ve uploaded a few files at the root level at the URL:

Any suggestion is appreciated. Thanks in advance.

Best regards,
Herman Tse


(David Wernhart) #4

Hey Herman,

Have you tried tapping on the screen with the demo project open?
The ad is supposed to toggle on and of with tapping.

Hope that helps!

Best regards,
David


(Herman Tse) #5

Hi David,

Thanks for your prompt reply.

I tried tapping on the screen and receive Gdx.app.log message indicated ‘showing’ or ‘hiding’ of ads but cannot see any visual changes on the screen.

I managed to upload my complete code onto GitHub as below URL:

Best regards,
Herman


(Herman Tse) #6

… and I’m using framework GoogleMobileAdsSdkiOS-7.24.1

Best regards,
Herman


(Herman Tse) #7

Hi David,

I solved it! I connected the device for testing and thus forget to turn on network (i.e. wifi connection). I turned on wifi and started the app and saw the test banner now! Problem solved!

Thanks for your help and attention anyway!

Best regards,
Herman


(David Wernhart) #8

Nice to hear that this worked for you!
Sometimes the most trivial problems consume the most of your time.

Best regards,
David


(Herman Tse) #9

Hi David,

Any sample code for Interstitial ads. I tried but can only display once and the interstitialDidDismissScreen is not called. In there I tried to re-alloc the GADInterstitial and make the ads load.

Best regards,
Herman


(David Wernhart) #10

Hey Herman,

I solved the problem with loading the ad with a recursive call of an initialization method, like that:

initialization method:

public void createAdmobInterstitial() {
admobInterstitial = GADInterstitial.alloc().initWithAdUnitID(admobAdId);
        admobInterstitial.setDelegate(new GADInterstitialDelegate() {
            @Override
            @Selector("interstitialDidReceiveAd:")
            public void interstitialDidReceiveAd(GADInterstitial ad)
            {
                Gdx.app.log("admob","interstitial received an ad");
            }
            @Override
            @Selector("interstitialDidDismissScreen:")
            public void interstitialDidDismissScreen(GADInterstitial ad) {
                Gdx.app.log("admob","interstitial did dismiss screen");
                createAdmobInterstitial();
            }
        });

        GADRequest request = GADRequest.request();

        admobInterstitial.loadRequest(request);
        Gdx.app.log("admob","new interstitial initialized");
    }

actual method to show the interstitial:

public void showAdmobInterstitial(){
        if(admobInterstitial.isReady()) {
            admobInterstitial.presentFromRootViewController(myApplication.getUIViewController());
            Gdx.app.log("admob", "is presenting interstitial");
        }

        else{
            Gdx.app.log("admob", "interstitial is not ready yet");
        }
    }

hope that helps!

Best regards,

David


(Herman Tse) #11

Hi David,

Thanks for your thoughts.

I based on your thoughts and made a twist and solved the problem:

I have similar initialization method but without the setDelegate call.

In actual show method, I made use of the ‘not ready’ else clause to call the initialization method. Next time the show method is called will display the interstitial ads.

This way I avoid define a recursive method.

Thanks for pointing out the right direction.

Best regards,
Herman


(Fran Marzoa) #12

Hey,

Thanks for taking your time of creating and sharing this example. I have cloned it but got into trouble when trying to build it. The problem is that in the IOSLauncher class there is this call within the createApplication method:

return new IOSApplication(new MyGdxGame(), config);

But MyGdxGame constructor is actually declared as follows:

public MyGdxGame(adDelegate ads)

There’s no constructor without arguments in that class, thus I’m getting this compiler error:

error: constructor MyGdxGame in class MyGdxGame cannot be applied to given types;
required: adDelegate
found: no arguments
reason: actual and formal argument lists differ in length


Admob integration for iOS