Android Question [Solved] Initialize MobileAds

asales

Expert
Licensed User
Longtime User
In this link:
https://developers.google.com/admob/android/quick-start#initialize_mobileads
I have this information:
Before loading ads, have your app initialize the Mobile Ads SDK by calling MobileAds.initialize() with your AdMob App ID. This needs to be done only once, ideally at app launch.

I use banners, interstitial and native ads.
I need to do this?
If yes, how I can initialize the AdMob App ID?

Thanks in advance for any help.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Seems like the ads work without this call. You can call it with:
B4X:
Dim ctxt As JavaObject
ctxt.InitializeContext
MobileAds.InitializeStatic("com.google.android.gms.ads.MobileAds")
MobileAds.RunMethod("initialize", Array(ctxt, YourAdMobAppId))

Best to do it in Activity_Create when FirstTime is True.
 
Last edited:
Upvote 0

asales

Expert
Licensed User
Longtime User
B4X:
MobileAds.InitializeStatic("com.google.android.gms.ads.MobileAds")
MobileAds.RunMethod("initialize", Array(ctxt, YourAdMobAppId))
MobileAds is JavaObject, correct?
B4X:
Dim MobileAds As JavaObject
What is ctxt?
How I initialize it?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

asales

Expert
Licensed User
Longtime User
This is my final code. Thanks!

B4X:
If FirstTime Then
    Dim ctxt As JavaObject
    ctxt.InitializeContext
    Dim MobileAds As JavaObject
    MobileAds.InitializeStatic("com.google.android.gms.ads.MobileAds")
    MobileAds.RunMethod("initialize", Array(ctxt, "ca-app-pub-3940256099942544~3347511713"))  'Sample ID
End If
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
Is this to get native ads working with the admob for firebase library?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

sorex

Expert
Licensed User
Longtime User
I still don't have the ability to select/see Native ads when going to the "Add unit". Not sure why but a lot of people don't see it.
 
Upvote 0

asales

Expert
Licensed User
Longtime User
I still don't have the ability to select/see Native ads when going to the "Add unit". Not sure why but a lot of people don't see it.
This is not still release to all users.
I talked with a Google account manager and he says that you will see this ads only if your account has a manager.
 
Upvote 0
Top