Android Question Rewarded Ads....

eps

Expert
Licensed User
Longtime User
I set this up for a new App I've created.

The test reward ad showed and I thought it was all done and dusted, but now I'm not so sure that it is working any more - maybe due to sdk and b4a updates and my having misread or missed some of the requirements.

My own reward ad wasn't showing - I had a return code of 0.

So I reverted back to the test reward ad and it also gives a return code of 0. Which surely isn't possible is it? That ad should 'always' be available. I'll post some code in a moment - but was just wondering if anyone else had issues around newer sdk or b4a versions??
 

eps

Expert
Licensed User
Longtime User
B4X:
    rewardAd.Initialize("rewardAd")
    rewardAd.LoadAd("ca-app-pub-3940256099942544/5224354917")  'test id

I've also got this

B4X:
#AdditionalJar: com.google.android.gms:play-services-base

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

I get a 0 response for the above.

and am using v1.52 of the FireBaseAdmob library with B4A 8.5 minSDK 18 and targetSDK 27

So what am I doing wrong here? I'm sure it's probably obvious to someone but I just can't fathom it and it feels like I've been going round and round in ever inter-entwining and decreasing circles.
 
Upvote 0

eps

Expert
Licensed User
Longtime User
Is it that Admob recognises my gmail account as the primary one and therefore doesn't want to show ads to me?

I've tried using this, but it just errors...

B4X:
    Dim builder As JavaObject
    builder.InitializeNewInstance("com.google.android.gms.ads.AdRequest.Builder", Null)
    builder.RunMethod("addTestDevice", Array("ID REMOVED"))
    Dim jo As JavaObject = rewardAd
    jo.RunMethod("loadAd", Array(builder.RunMethod("build", Null)))

LoadAd not matched...
 
Last edited:
Upvote 0

eps

Expert
Licensed User
Longtime User
Hmm... I seem to have 2 Admob API keys for this App.... One for the App and one for Rewarded Ads... I guess I'm supposed to use the Rewarded Ads one - but should the google-services.json be linked to the app one or the Rewarded Ads one?
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
I have rewarded ads running in one of my apps. I don't use:
B4X:
#AdditionalJar: com.google.android.gms:play-services-base
but I do use:
B4X:
#AdditionalJar: com.google.android.gms:play-services-core

The rest of my implementation is the same as your first example - ie:
B4X:
rewardAd.Initialize("rewardAd")
    rewardAd.LoadAd("ca-app-pub-3940256099942544/5224354917")
& it works fine.

- Colin.
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
I think eps wants to use the GDPR proof method.

Your method is not correct for EU people, Colin. :)
The personalized trigger is not involved with the regular .loadAd

I don't know how to do it right for rewarded videos tho as I only tested it with interstitials.
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
I think eps wants to use the GDPR proof method.

Your method is not correct for EU people, Colin. :)
The personalized trigger is not involved with the regular .loadAd

I don't know how to do it right for rewarded videos tho as I only tested it with interstitials.
I didn't get that from his post. I just got that he was trying different ways of getting it to work.

My implementation is fine for EU people, because I also use interstitials in the same app & show the consent form when I initialise them at the start of the app. :)

- Colin.
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
I didn't get that from his post. I just got that he was trying different ways of getting it to work.

My implementation is fine for EU people, because I also use interstitials in the same app & show the consent form when I initialise them at the start of the app. :)

- Colin.
Actually, I tell a lie. I show the consent form from the Starter service.

- Colin.
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
showing the consent form is 1 thing. showing non-personlized interstitials and rewarded videos is another thing.

for interstitials you need to use that builder method based on that selected setting.
so I guess you need to do the same thing for the rewarded videos that's why he posted that javaobject code.
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
showing the consent form is 1 thing. showing non-personlized interstitials and rewarded videos is another thing.

for interstitials you need to use that builder method based on that selected setting.
so I guess you need to do the same thing for the rewarded videos that's why he posted that javaobject code.
Yeah, you're right. I do it with the interstitials, but I guess I overlooked it on the rewarded ads.

- Colin.
 
Upvote 0

eps

Expert
Licensed User
Longtime User
Thanks everyone, I'll take a look in a moment... I was mainly looking to just get it all working again and then to consider the EU GDPR consent BS
 
Upvote 0

eps

Expert
Licensed User
Longtime User
I've put together a test app.... Which doesn't work either.

So far I've got it to tell me this :

Use AdRequest.Builder.addTestDevice("REMOVED") to get test ads on this device.

So if I add the code for that, as above it then tells me...

LoadAd not Matched..

So I'm at an impasse. I'll see if I can test on another device....
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
I've put together a test app.... Which doesn't work either.

So far I've got it to tell me this :

Use AdRequest.Builder.addTestDevice("REMOVED") to get test ads on this device.

So if I add the code for that, as above it then tells me...

LoadAd not Matched..

So I'm at an impasse. I'll see if I can test on another device....
So according to the AdMob documentation, the LoadAd method looks like this:

B4X:
private void loadRewardedVideoAd() {
    mRewardedVideoAd.loadAd("ca-app-pub-3940256099942544/5224354917",
            new AdRequest.Builder().build());
}

That being the case, have you tried:

B4X:
    Dim builder As JavaObject
    builder.InitializeNewInstance("com.google.android.gms.ads.AdRequest.Builder", Null)
    builder.RunMethod("addTestDevice", Array("ID REMOVED"))
    Dim jo As JavaObject = rewardAd
    jo.RunMethod("loadAd", Array("ca-app-pub-3940256099942544/5224354917", builder.RunMethod("build", Null)))

- Colin.
 
  • Like
Reactions: eps
Upvote 0

eps

Expert
Licensed User
Longtime User
Hi Colin, I haven't - I'll give it a whirl, thanks!

That's great - thank you! It didn't work initially but on reinstalling it does work. I now need to unpick my code to work out why my actual app doesn't work currently. Cheers!

:)
 
Last edited:
Upvote 0

eps

Expert
Licensed User
Longtime User
google-services.json is not related to the ads.

Ah - I see what the problem is here, I included :
B4X:
CreateResourceFromFile(Macro, FirebaseAnalytics.Firebase)

As well, which wanted the json file included. Now I've commented that Macro out it doesn't require the json file :)

Now I just use :

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

eps

Expert
Licensed User
Longtime User
This all works now, THANK YOU @Computersmith64 !! :)

It even displays 'my' ads.

I've put the analytics back in - the .json file for this is the App one. You can generate a 'json file for the rewardedAd Unit as well, which is where I was coming unstuck I think. The consent form displays and I can select it, etc.. it's quite ugly and painful but at least that works. Of course my next question is how to integrate the part where it talks about a Paid For version - or do I just not mention that on the Consent Form and then offer one on the App Store? Hm.... We're a bit of a way away from that!

:D
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
This all works now, THANK YOU @Computersmith64 !! :)

It even displays 'my' ads.

I've put the analytics back in - the .json file for this is the App one. You can generate a 'json file for the rewardedAd Unit as well, which is where I was coming unstuck I think. The consent form displays and I can select it, etc.. it's quite ugly and painful but at least that works. Of course my next question is how to integrate the part where it talks about a Paid For version - or do I just not mention that on the Consent Form and then offer one on the App Store? Hm.... We're a bit of a way away from that!

:D
Glad you got it working. I would recommend only having one app & using an IAP. I have done it both ways (IAP & different paid version) & it's much easier to have the IAP as you don't have to update multiple versions all the time. Even when you use the same code base with different build configurations (which I do), it can get a bit messy, plus you have 2 separate apps to maintain on Play Store.

This is how I do it in Dice Match:

B4X:
Public Sub ConsentStateAvailable(user As Boolean)
    Dim consent As ConsentManager = Starter.consent
    If (consent.ConsentState = consent.STATE_UNKNOWN And consent.IsRequestLocationInEeaOrUnknown) Or user Then
        'Set last parameter to False if you don't want to show the "pay for ad-free" option.
        'Change privacy policy URL.
        consent.ShowConsentForm("https://www.facebook.com/notes/computersmith/computersmith-data-consent-policy/2049613211975625/", True, True, True)
        Wait For Consent_FormResult (Success As Boolean, UserPrefersAdFreeOption As Boolean)
        If Success Then
            Log($"Consent form result: ${consent.ConsentState}, AdFree: ${UserPrefersAdFreeOption}"$)
            If consent.ConsentState = consent.STATE_PERSONALIZED Or consent.ConsentState = consent.STATE_NON_PERSONALIZED Then
                If Starter.analytics.IsInitialized Then Starter.analytics.SendEvent(consent.ConsentState, Null)
                MsgboxAsync("Thank you! We will not ask you for your consent again. If you wish to change or cancel your consent, please use the Privacy option on the game menu.", "Consent Saved")
            Else if UserPrefersAdFreeOption Then
                Starter.wantsAdFree = True
                If Starter.analytics.IsInitialized Then Starter.analytics.SendEvent("AdFree", Null)
                MsgboxAsync("Thank you! You will be redirected to the purchase screen where you can buy the No Ads upgrade.", "Ad Free Option")
                Wait For MsgBox_Result(res As Int)
                StartActivity(Purchase)
            End If
        Else
            Log($"Error: ${LastException}"$)
        End If
    End If
       
End Sub

- Colin.
 
  • Like
Reactions: eps
Upvote 0

eps

Expert
Licensed User
Longtime User
Cheers - I'll take a look and digest... I had already decided to not have the 'Go for Paid App' option anyway and allow Users to select Personalised or Non-Personalised. Hopefully this will give them enough choices!
 
Upvote 0
Top