Android Question Google Admob


Active Member
Licensed User
Longtime User
Hi all

1. according to this tutorial I have created a b4a project and a new Firebase project through with the same package name.
2. I downloaded google-services.json and put it in the projects folder.
3. according to this tutorial I wrote this code, but it doesn't work:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private xui As XUI
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    Private BannerAd As AdView
    Private iAd As InterstitialAd
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Dim m As MobileAds
    Wait For (m.Initialize) MobileAds_Ready
    m.SetConfiguration(m.CreateRequestConfigurationBuilder(Array("77A04EE40B2AFED2AFC67701365187EC"))) 'optional. Array with test device ids. See unfiltered logs to find id.
    Dim AdaptiveSize As Map = GetAdaptiveAdSize
    'Add Private BannerAd As AdView in Globals sub
    BannerAd.Initialize2("BannerAd", "ca-app-pub-3940256099942544/6300978111",AdaptiveSize.Get("native"))
    Activity.AddView(BannerAd, 0, 0,  AdaptiveSize.Get("width"), AdaptiveSize.Get("height"))
    iAd.Initialize("iad", "ca-app-pub-3940256099942544/1033173712")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub GetAdaptiveAdSize As Map
    Dim ctxt As JavaObject
    Dim AdSize As JavaObject
    Dim width As Int = 100%x / GetDeviceLayoutValues.Scale
    Dim Native As JavaObject = AdSize.InitializeStatic("").RunMethod("getCurrentOrientationAnchoredAdaptiveBannerAdSize", Array(ctxt, width))
    Return CreateMap("native": Native, "width": Native.RunMethod("getWidthInPixels", Array(ctxt)), _
        "height": Native.RunMethod("getHeightInPixels", Array(ctxt)))
End Sub

Sub Ad_ReceiveAd
    Log("Adview received")
End Sub

Sub Ad_FailedToReceiveAd (ErrorCode As String)
    Log("Failed: " & ErrorCode)
End Sub

Sub Ad_AdClosed
End Sub

Sub Ad_AdOpened
End Sub
Sub iAd_ReceiveAd
    Log("IAd received. Now wait for the right moment to show the ad.")
    If iAd.Ready Then
        iAd.Show 'bad example. You should instead wait for the correct time and show it when it makes sense.
    End If
End Sub

Sub iAd_FailedToReceiveAd (ErrorCode As String)
    Log("Failed: " & ErrorCode)
End Sub

Sub iAd_AdClosed
End Sub

Sub iAd_AdOpened
End Sub

Manifest editor:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information:
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="29"/>
<supports-screens android:largeScreens="true"
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.LightTheme)
'End of default text.
CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)
CreateResourceFromFile (Macro, FirebaseAdMob.FirebaseAds)
AddReplacement($ADMOB_APP_ID$, ca-app-pub-9685574697212875/8070010520)

where can I find these IDs:
AddReplacement($ADMOB_APP_ID$, ca-app-pub-9685574697212875/8070010520) in the manifest editor.
BannerAd.Initialize2("BannerAd", "ca-app-pub-9685574697212875/8070010520",AdaptiveSize.Get("native"))
iAd.Initialize("iad", "ca-app-pub-9685574697212875/8070010520")

Knowing that I created the project through the admob console.



Active Member
Licensed User
Longtime User
thanks asales
but I can't find here my application that I create through console. Do I have to create it from scratch in this place?
Upvote 0


Active Member
Licensed User
Longtime User
now I created a project in Firebase and linked it to console, I got this error:

Logger connected to: 4200c4bef41824d3
--------- beginning of system
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Failed: {
  "Code": 3,
  "Message": "Publisher data not found. <https:\/\/\/admob\/answer\/9905175#9>",
  "Domain": "",
  "Cause": "null",
  "Response Info": {
    "Response ID": "null",
    "Mediation Adapter Class Name": "",
    "Adapter Responses": []
** Activity (main) Pause, UserClosed = false **
Upvote 0