Hi all
1. according to this tutorial I have created a b4a project and a new Firebase project through https://console.firebase.google.com/ 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:
Manifest editor:
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.
thanks.
1. according to this tutorial I have created a b4a project and a new Firebase project through https://console.firebase.google.com/ 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:
B4X:
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)
Activity.LoadLayout("Layout")
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"))
BannerAd.LoadAd
iAd.Initialize("iad", "ca-app-pub-3940256099942544/1033173712")
iAd.LoadAd
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub GetAdaptiveAdSize As Map
Dim ctxt As JavaObject
ctxt.InitializeContext
Dim AdSize As JavaObject
Dim width As Int = 100%x / GetDeviceLayoutValues.Scale
Dim Native As JavaObject = AdSize.InitializeStatic("com.google.android.gms.ads.AdSize").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
Log("Closed")
End Sub
Sub Ad_AdOpened
Log("Opened")
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
Log("Closed")
End Sub
Sub iAd_AdOpened
Log("Opened")
End Sub
Manifest editor:
B4X:
'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: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="29"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="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.
thanks.