Admob help

Jimmy

Active member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
715
Please can someone guide me how do I get the example to work?
It keep telling me "identifier ShowAd not found."

Code:
#If TARGET<>"android" And TARGET<>"ios"
#Error "Admob is only supported on Android and iOS targets"
#End

#ADMOB_PUBLISHER_ID="ca-app-pub-3940256099942544/6300978111"    'replace with id from your admob account
#ADMOB_ANDROID_TEST_DEVICE1="TEST_EMULATOR"
#ADMOB_ANDROID_TEST_DEVICE2="TEST_EMULATOR"

Import mojo
Import brl.admob

Class MyApp Extends App

  Field admob:Admob
  Field interstitialAdmob:AdmobInterstitial
  Field layout:=1
  Field state:=1

  Method OnCreate()
    admob=Admob.GetAdmob()
    admob.ShowAdView 1,layout
    interstitialAdmob=AdmobInterstitial.GetAdmobInterstitial("ca-app-pub-3940256099942544/1033173712")
    SetUpdateRate 60
  End

  Method OnUpdate()
    If MouseHit( 0 )
      If state = 3
        admob.HideAdView
        state+=1
      Else If state = 1
        layout+=1
        If layout=7 layout=1
        admob.ShowAdView 1,layout
        state+=1
      Else If state = 2
        admob.HideAdView
        interstitialAdmob.ShowAd
        state+=1
      End
    End
  End

  Method OnRender()
    Local en:="disabled"
    If state=2 en="enabled"
    Cls
    PushMatrix
      Scale 2,2
      DrawText "Click to toggle ads! ads are currently "+en,DeviceWidth/4,DeviceHeight/4,.5,.5
    PopMatrix
  End

End

Function Main()
  New MyApp
End
 

Martin

Active member
CX Code Contributor
3rd Party Module Dev
Tutorial Author
Joined
Jun 19, 2017
Messages
334
That's probably an outdated example. For interstitial ads use: ShowAdViewInterstitial

So replace
Code:
interstitialAdmob.ShowAd
with
Code:
interstitialAdmob.ShowAdViewInterstitial
 

Jimmy

Active member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
715
Thanks, but it just gives me a black screen, did I put the id correctly though bc mine looks different than the one in the example, the intertestial id had the same format though so I'm fairly confident that one is correctly made.

my id goes like this #ADMOB_PUBLISHER_ID="pub-################"
I tried adding "ca-" in the beginning but still black screen.
 
Last edited:

Martin

Active member
CX Code Contributor
3rd Party Module Dev
Tutorial Author
Joined
Jun 19, 2017
Messages
334
TBH I never tried interstitial ads. Does the test ad show up?
 

Jimmy

Active member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
715
I don't have a Android device to try out on any more for today. I never tried the default ID I will as soon as I can.
 

Jimmy

Active member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
715
It had a slash in its ID.. very weird?

I see that you can "Add test device" in their website, maybe that's what is missing for me?
 

Martin

Active member
CX Code Contributor
3rd Party Module Dev
Tutorial Author
Joined
Jun 19, 2017
Messages
334
No, you don't have to add test devices. Would have to check, all I know is that the look of their IDs have changed lately.

Mine (working one) looks like that for instance:
Code:
#ADMOB_PUBLISHER_ID="ca-app-pub-69037177xxxxxxxx/9125xxxxxx"
 

Jimmy

Active member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
715
When i get the howto instructions I find this :

"To place the ad unit inside your app, follow these instructions:
Complete the instructions in the Google Mobile Ads SDK guide using this app ID:

Demo app
ca-app-pub-################~##########
Follow the interstitial implementation guide to integrate the SDK. You'll specify ad type and placement when you integrate the code using this ad unit ID:

demoad
ca-app-pub-################/##########
Review the AdMob policies to ensure your implementation complies."


Maybe ca-app-pub-################~########## is the new format of publisher ID (actually App-ID, but Isn't that was is wanted, Publisher ID is really short?). I wish I had an device to try on right now.
 
Last edited:

Martin

Active member
CX Code Contributor
3rd Party Module Dev
Tutorial Author
Joined
Jun 19, 2017
Messages
334
Well be careful with that '~'. I know it's part of the ID now? In Monkey/Cerberus it's the escape sequence (so like normally '\').

So to encode that '~' itself you have to write '~~'

But yeah, without a real device it's impossible to see if it really works.
 

Jimmy

Active member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
715
Thanks. You were ahead of me regarding the tilde. Will test when possible!
 

Martin

Active member
CX Code Contributor
3rd Party Module Dev
Tutorial Author
Joined
Jun 19, 2017
Messages
334
All I can say is that with real ads at least on my side it could take up to 24h until they really showed up! So it's save to assume that it works when the test ads are working. But again - that's on a real device and I don't know it interstitial banners currently work, I just tried classic banners.
 

Jimmy

Active member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
715
How would you get normal banners I don't see an example for that?
 

Martin

Active member
CX Code Contributor
3rd Party Module Dev
Tutorial Author
Joined
Jun 19, 2017
Messages
334
Oh that's done in that example as well:

Code:
admob.ShowAdView 1,layout

in my particular game:
Code:
Class MauMau Extends App
  #If TARGET="ios" Or TARGET="android"
    Field _admob:Admob
    Field _layout:Int = 5
    Field _enabled:Bool = True
  #End

  Method OnCreate:Int()
  ...
    #If TARGET="ios" Or TARGET="android"
      _admob = Admob.GetAdmob()
      If( gIsFullVersion )
        _admob.HideAdView()
      Else
        _admob.ShowAdView( 2, _layout )
      End If
    #End
    Return 0
  End Method

...
 

Jimmy

Active member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
715
Is Admob fully compatible with Mojo2?
 

Martin

Active member
CX Code Contributor
3rd Party Module Dev
Tutorial Author
Joined
Jun 19, 2017
Messages
334
I think so. Because it's already above all that stuff, it's view/layout based so doesn't care about the canvas. It's like an own frame on top.
 

Jimmy

Active member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
715
Nothing worked, not even the standard demo. Before i *DID* get a banner this was way back like 6 months or so. but when you clicke again it deissapeared for good (which it shouldnt if i uunderstood the demo).

But now this time... nothing. I tried both kinds of ads for mine, and the standard demo.
 

MikeHart

Administrator
Joined
Jun 19, 2017
Messages
3,035
I think the SDK needs to be updated. Android has quite a few changes these days. Definitely needs to be looked into before the next release.
 
Top Bottom