Android Question user consent form visible only in debug mode

seby8181

Member
Licensed User
Longtime User
thanks for reply!

this is main code:

B4X:
Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   Public consent As ConsentManager
   Dim AdView1 As AdView

End Sub


'show the consent form if needed
Sub ConsentStateAvailable

    consent  = Starter.consent
    If consent.ConsentState = consent.STATE_UNKNOWN And consent.IsRequestLocationInEeaOrUnknown Then
        'Set last parameter to False if you don't want to show the "pay for ad-free" option.
        'Change privacy policy URL.
        'Sleep(5000)
        Log("a")
        consent.ShowConsentForm("https://www.google.com/policies/technologies/partner-sites/", True, True, False)
        'Sleep(5000)
        Log("b")
        Wait For Consent_FormResult (Success As Boolean, UserPrefersAdFreeOption As Boolean)
        'Sleep(5000)
        Log("b")
        If Success Then
            Log($"Consent form result: ${consent.ConsentState}, AdFree: ${UserPrefersAdFreeOption}"$)
        Else
            Log($"Errore: ${LastException}"$)
        End If
    End If
    LoadAd 
End Sub

'load ads:
Sub LoadAd
    Dim builder As AdRequestBuilder
    builder.Initialize
    
    If consent.IsRequestLocationInEeaOrUnknown Then
        If consent.ConsentState = consent.STATE_NON_PERSONALIZED Then
            builder.NonPersonalizedAds
        Else if consent.ConsentState = consent.STATE_UNKNOWN Then
            Return
        End If
    End If
    'builder.AddTestDevice("D4AC977CA12D122C4563730CC762C302")
    'adview1.LoadAdWithBuilder(builder)
    AdView1.Initialize2("AdView1","ca-app-pub-3737348979012626/9909374758", AdView1.SIZE_SMART_BANNER)
    Activity.AddView(AdView1, 0, 100%y -50dip, 100%x, 50dip)
    AdView1.LoadAdWithBuilder(builder)
    AdView1.Visible = True
End Sub

this is starter module code:

B4X:
Sub Service_Create
    'This is the program entry point.
    'This is a good place to load resources that are not specific to a single activity.
    consent.Initialize("consent")
    '    consent.AddTestDevice("D4AC977CA12D122C4563730CC762C302")
    '    consent.SetDebugGeography(True) 'comment for regular operation
    consent.RequestInfoUpdate(Array("pub-3737348979012626"))
    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)
  
    Do While IsPaused(Main)
        Sleep(100)
    Loop
    CallSubDelayed(Main, "ConsentStateAvailable")
End Sub

...and this is log:

B4X:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Consent state: UNKNOWN
EU: true
a
b

in RELEASE MODE i don't whatch consent form
...BUT...
in DEBUG MODE it work perfectly!

thanks a lot!!! ;)
 
Upvote 0
Top