Android Question Probleme with FirebaseAdmob

Lego Jérôme

Member
Licensed User
I followed this tutorial : https://www.b4x.com/android/forum/threads/integrating-firebase-services.67692/

1) I have install all recommended items with B4A Sdk Manager tool.
2) My Firebase was created 2 days ago. with good package.name
3) I have download "google-services.json" from web ("firebase")
4) I did not really understand what I had to put in the manifest of the coup I joined you the code
5) When I run a test the ads are displayed, but when i put my "ca-app-pub-xxxxx/xxxxx", ads are no longer displayed on the screen

i have B4A version 8

Manifest Code :

HTML:
'AdMob
AddApplicationText(
<meta-data android:name="com.google.android.gms.version"
  android:value="@integer/google_play_services_version"/>
<activity android:name="com.google.android.gms.ads.AdActivity"
  android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
)
'End of AdMob

B4X:
Sub Globals
    Private BannerAd As AdView
    Private IAd As InterstitialAd
End Sub

Sub Activity_Create(FirstTime As Boolean)

    
    BannerAd.Initialize2("BannerAd", "ca-app-pub-8935643716482518~7951009036", BannerAd.SIZE_SMART_BANNER)
    Dim height As Int
    If GetDeviceLayoutValues.ApproximateScreenSize < 6 Then
        'phones
        If 100%x > 100%y Then height = 32dip Else height = 50dip
    Else
        'tablets
        height = 90dip
    End If
    Activity.AddView(BannerAd, 0dip, 100%y - height, 100%x, height)
    BannerAd.LoadAd
    IAd.Initialize("iad", "ca-app-pub-3940256099942544/1033173712")
    IAd.LoadAd
    
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub


Sub Activity_Resume
    
End Sub

Sub Activity_Click
    If IAd.Ready Then IAd.Show
End Sub
 

asales

Expert
Licensed User
Longtime User
When you create an ad in Admod there are 2 codes.
The code of the banner with the character " ~ " is not the correct code.
Access the Admob Console and see the code that have a character " / " instead the " ~".
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
Which ads aren't displayed? The banner or the interstitial, or both? For the interstitial, try implementing the FailedToReceiveAd callback. At least then you'll be able to see what/if the error code is & investigate from there:

B4X:
Private Sub IAd_FailedToReceiveAd(ErrorCode As String)
    Log("failed to load ad: " & ErrorCode)
End Sub

- Colin.
 
Upvote 0

Lego Jérôme

Member
Licensed User
In log the error message is "failed to load ad:0"

all ads arn't displayed. But in test, banner and interstitial are displayed
I'm not mistaken ID code that I have to go back it's the one that went in the picture ?
 

Attachments

  • Sans titre.png
    Sans titre.png
    48.5 KB · Views: 235
Last edited:
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
In log the error message is "failed to load ad:0"

all ads arn't displayed. But in test, banner and interstitial are displayed
I'm not mistaken ID code that I have to go back it's the one that went in the picture ?

If the app is showing test ads correctly, then the ads are working properly. It could simply be that there were no ads available for your region/demographic at the time you requested them. Yes, you use the Ad unit ID shown under Apps->[Ad Name]->Ad units in your AdMob console.

- Colin.
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
how could I intercept available ad ?
it seems odd to me that I did not manage to recover any.
It does happen. Fill rates are rarely 100%. For testing purposes, you could try sending another request if you get a failed to load message. I wouldn't put that in a release though because you could end up in a loop making constant requests if there are no ads available.

- Colin.
 
Upvote 0

Lego Jérôme

Member
Licensed User
I would not have to activate permission to go on the internet by chance.
I tried the following code:

B4X:
Sub Activity_Click
    If IAd.Ready Then
        IAd.Show
    Else
        IAd.LoadAd
    End If
End Sub
 

Attachments

  • Sans titre.png
    Sans titre.png
    23 KB · Views: 234
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
I would not have to activate permission to go on the internet by chance.
I tried the following code:

B4X:
Sub Activity_Click
    If IAd.Ready Then
        IAd.Show
    Else
        IAd.LoadAd
    End If
End Sub
If you are receiving test ads, then I'd say it's probably not necessary - but if you have included the Firebase Base snippet in your manifest per the instructions in the Firebase tutorial, then that permission will already be there. You can check which permissions are active in your app by clicking on the "List Permissions" button at the bottom of the Logs tab in the B4A IDE.

- Colin.
 
Upvote 0

Lego Jérôme

Member
Licensed User
B4X:
CreateResourceFromFile(Macro, FirebaseAdMob.FirebaseAds)

if i add this line of code in my manifest I get this problem in log : "file not found firebaseAds.b4x_excluded"
i think it's not good ...
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
B4X:
CreateResourceFromFile(Macro, FirebaseAdMob.FirebaseAds)

if i add this line of code in my manifest I get this problem in log : "file not found firebaseAds.b4x_excluded"
i think it's not good ...
Can you post your manifest?
 
Upvote 0

Lego Jérôme

Member
Licensed User
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="5" android:targetSdkVersion="26"/>
<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.DarkTheme)
'End of default text.

AddManifestText(
<uses-permission
  android:name="android.permission.WRITE_EXTERNAL_STORAGE"
  android:maxSdkVersion="18" />
)


'AdMob
AddApplicationText(
<meta-data android:name="com.google.android.gms.version"
  android:value="@integer/google_play_services_version"/>
<activity android:name="com.google.android.gms.ads.AdActivity"
  android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
)
'End of AdMob

Yes of course !
when I get to display ads it's with this code, but according to the following tutorial : https://www.b4x.com/android/forum/threads/integrating-firebase-services.67692/
I should not use the passage with "AdMobApplicationText...."
But rather use these lines there.
in fact I am a little lost because there are several different tutorials on the forum.


B4X:
CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)
CreateResourceFromFile(Macro, FirebaseAnalytics.Firebase)
CreateResourceFromFile(Macro, FirebaseAdMob.FirebaseAds)
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
Yes - you should use the macros, but only if you are using B4A v8+ according to the tutorial. I'm surprised you even got test ads using the AddApplicationText entries, because you didn't include the Google Play Base or Firebase Base in your manifest.

Did you put the google-services.json file in the root directory of your project?

Can you get back to where you are receiving test ads? If you can, then you are properly set up - so after that if you change the Ad Unit ID to the correct one for your ad & you don't see any ads, then it must be because AdMob isn't providing them (or you are using the wrong ad unit id).

- Colin.
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User

OK - so everything is working as it should. Now if you change the Ad Unit IDs to the correct IDs for your AdMob ads, you should start seeing real ads. Once you have sent a few requests (& waited a while) take a look at the Reports section in your AdMob console & you should see Network Requests, Match Rate & Impressions. If you aren't seeing any Requests, then your calls to LoadAd aren't getting through (double check your ad ids). If you're seeing Requests, but the Match Rate is 0, then AdMob is just not serving ads for some reason. The Impressions tells you how many ads you actually showed.

If you still can't get it to work, upload the project & I'll run it with my own ad ids & see if it shows ads. Use File->Export As Zip to create a zipped project, then upload it to here.

- Colin.
 
Upvote 0

Lego Jérôme

Member
Licensed User
my console says everywhere 0

i can't upload my project.zip because the uploaded file is too large... (26 300ko)
i can send you by wetransfer.
 

Attachments

  • Sans titre.png
    Sans titre.png
    35.8 KB · Views: 210
Upvote 0
Top