Android Question AdMob and user consent

06Pierrick06

Member
Licensed User
Hi guys

I have spent some hours reading discussions about Admob and users consent and I must confess I'm lost.
This topic is very old and I found so many articles talking about outdated versions of Admob or features which have been replaced that I cannot get any code working.
Is there any possibility to get an actualized step by step article with B4A 9.50 and taking into account GDPR constraints in Europe ?

A working B4A exemple would help a lot.

Sorry in advance if I'm asking for too much.
 

06Pierrick06

Member
Licensed User
My current code is the following :

1) Manifest (where xxxxx~yyyyy is my AdMob Application ID)

B4X:
'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
AddReplacement($ADMOB_APP_ID$,
ca-app-pub-xxxxxxxxxxxx~yyyyyyyyy)

2) In Sub Globals

B4X:
Public consent As ConsentManager
Private BannerAd As AdView
Private IAd As InterstitialAd
Dim MobileAds As MobileAds

3) In Activity_Create (where zzzzz is my Ad ID)

B4X:
MobileAds.Initialize
BannerAd.Initialize2("BannerAd", "ca-app-pub-zzzzzzzzzzzzzzzzzzz", BannerAd.SIZE_SMART_BANNER)
 consent.Initialize("consent")

consent.RequestInfoUpdate(Array("pub-xxxx"))
    Wait For consent_InfoUpdated (Success As Boolean)
    If Success = False Then
        Log($"Error getting consent state: ${LastException}"$)
    End If
    Log($"Consent state: ${consent.ConsentState}"$)
    Log("EU: " & consent.IsRequestLocationInEeaOrUnknown)
  
    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


When I execute on emulator, I get a test AD banner displaying "Nice Job. This is a 320x200 test AD" (while I used my real AdMob IDs)
When I execute on physical device, no Ad is displayed and I get error code = 3.

In both cases log displays 3 messages :
Error getting consent state: java.lang.Exception: Could not parse Event FE preflight response.
Consent state: UNKNOWN
EU: false

NB : I also read elsewhere in the forum I need to generate a "google-services.json" but don't know if it is still necessary or not.

As I said ... I'm lost :)
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The tutorial is not very old. It was updated a few months ago and should be still relevant: https://www.b4x.com/android/forum/threads/firebaseadmob-and-user-consent.93347/

When I execute on physical device, no Ad is displayed and I get error code = 3.
This is not related to the consent issue.
Error code 3 = no fill. It usually resolves automatically after a day or two. Worth testing it on a different device as Google might have "marked" your device as a development device.

Error getting consent state: java.lang.Exception: Could not parse Event FE preflight response.
This issue might be related to a wrong publisher id: https://github.com/googleads/googleads-consent-sdk-android/issues/39
 
Upvote 0

06Pierrick06

Member
Licensed User
Thanks Erel for your reply.
Admob worked the day after. As you said, my Admob account needed some time to become active.
What is still strange to me is that my code never managed the consent form (just request info update) but everything works like a charm.
 
Upvote 0
Top