Android Tutorial FirebaseAdMob - Rewarded video ads

Erel

Administrator
Staff member
Licensed User
Edit: Google AdMob does support rewarded ads without mediation.
You can use this unit id to test it: rewardAd.LoadAd("ca-app-pub-3940256099942544/5224354917")
Make sure to use FirebaseAdMob v1.51+

FirebaseAdMob v1.30 adds support for rewarded video ads. Rewarded video ads are video ads where the user is rewarded if he watches the full video.
How is the user rewarded is up to you. In many games for example, the users will receive an extra life if they watch the video ad.

Google AdMob do not provide these ads. You need to use the mediation feature to add an ad network that does support rewarded videos. You can see the features that each ad network supports here: https://firebase.google.com/docs/admob/android/mediation-networks#supported-ad-formats
I've tested it with InMobi.

The first step is to integrate the third party ad network as explained here: AdMob Mediation (with InMobi)

Working with RewardedVideoAd is similar to working with InterstitialAds. You first need to call LoadAd. Note that the ad unit is passed to the LoadAd method and not to the Initialize method.

The ReceiveAd event will be raised when an ad is ready. Now you can call Ad.Show to show the ad. If the user will fully watch the ad then the Rewarded event will be raised.

Example:
B4X:
Sub Globals
   Private ad As RewardedVideoAd
End Sub

Sub Activity_Create(FirstTime As Boolean)
   ad.Initialize("ad")
End Sub

Sub Activity_Resume
   ad.LoadAd("ca-app-pub-12345675929340/33333326118")
End Sub

Sub ad_ReceiveAd
   Log("Ad received. Now wait for the right moment to show the ad.")
End Sub

Sub Ad_Rewarded (Item As Object)
   'Item is currently not used
   ToastMessageShow("You are rewarded!!!", True)
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 Activity_Click
   If ad.Ready Then ad.Show
End Sub
 
Last edited:

Davin

Member
Licensed User
erel, i dont know what i do wrong. but before.. i try the code, and i get the video ads running.

but now.. i only get error code : 3.. which is ads not serving at all..

even when i try to use test ads. it doesnt show a thing.
 

Davin

Member
Licensed User
i got something like this
B4X:
10-05 21:39:51.337 3255 3262 I art : Thread[2,tid=3262,WaitingInMainSignalCatcherLoop,Thread*=0x8ee0b000,peer=0x947e90a0,"Signal Catcher"]: reacting to signal 3
10-05 21:39:51.448 3255 3262 I art : Wrote stack traces to '/data/anr/traces.txt'
10-05 21:39:51.450 11598 11598 W Ads : Failed to load ad: 3
10-05 21:39:51.452 11598 11598 I B4A : sending message to waiting queue (ad_failedtoreceivead)
10-05 21:39:51.455 5527 5527 I B4A : sending message to waiting queue (ad_failedtoreceivead)
10-05 21:39:51.573 3619 3624 I art : Thread[2,tid=3624,WaitingInMainSignalCatcherLoop,Thread*=0x8ee0b000,peer=0x948010a0,"Signal Catcher"]: reacting to signal 3
10-05 21:39:51.746 3619 3624 I art : Wrote stack traces to '/data/anr/traces.txt'
10-05 21:39:51.746 3632 3637 I art : Thread[2,tid=3637,WaitingInMainSignalCatcherLoop,Thread*=0x8ee0b000,peer=0x948010a0,"Signal Catcher"]: reacting to signal 3
10-05 21:39:51.888 3643 3649 I art : Thread[2,tid=3649,WaitingInMainSignalCatcherLoop,Thread*=0x8ee0b000,peer=0x948020a0,"Signal Catcher"]: reacting to signal 3
10-05 21:39:51.893 3632 3637 I art : Wrote stack traces to '/data/anr/traces.txt'
10-05 21:39:52.046 3643 3649 I art : Wrote stack traces to '/data/anr/traces.txt'
and actualy the ads is loaded

B4X:
10-05 21:38:41.781 11305 11305 D InMobiAdapter: initialize called from InMobiAdapter.
10-05 21:38:41.787 11305 11305 W Ads : Server parameters: {"gwhirl_share_location":"1","accountid":"xxxxx","placementid":"xxxx"}
10-05 21:38:41.788 11305 11305 D InMobiAdapter: Bundle extras are null
but no sign of the ads
 

Davin

Member
Licensed User
Not sure. Does it happen if you create a new project with only the ads related code?
yes. i make a new project. and basically copy and paste your code with my admob id.

still get error failed:3
 

capisx

Member
Licensed User
erel, i dont know what i do wrong. but before.. i try the code, and i get the video ads running.

but now.. i only get error code : 3.. which is ads not serving at all..

even when i try to use test ads. it doesnt show a thing.
I got this problem too, i've test this rewarded video ads more than a week and it's still show error code: 3. Tested with the latest firebase admob lib v1.31 with the same result. I've checked the mediation report and the ads request was reported in that report but with 0,00% fillrate, it looks like the request was not submitted to inmobi server.
 

Davin

Member
Licensed User
+1 here.. soo.. is there any possibilities that someone can release the other library .. for unity ads maybe ?
 

Davin

Member
Licensed User
Tried the v5.31 and it works, the rewarded ads was shown in landscape orientation despite my app in portrait orientation.
Thanks a lot Erel :), i hope you will add another tutorial to integrate the third party ad network like Vungle using admob mediation.
this work well with me too. but .. damn me. i try with 6.0.1 and now ads not displayed. can u upload your libadapterinmobi file that work with 5.3.1 ?
 

seanfogg

Member
Licensed User
Hi, I have an issue which is driving me mad, as soon as I invoke the Show Method the video plays but the background process restarts the main activity_create which causes all sorts of problems. With interstitial ads the main activity process is paused until the ad is closed and then continues as normal, is there anyway I can replicate this action while the video is playing then resume after it is closed?
 

seanfogg

Member
Licensed User
I've answered my own question, had to add a new activicty and pass all the video ad processing to that, still had a lot of problems returning back to the main activity but managed to figure it out :)
 

seanfogg

Member
Licensed User
Hi, got another question, is there any way of trapping whether a user has clicked through during or at the end of a video? I know that the rewarded event fires if the video finishes but can you tell if they clicked the ad itself? I am thinking of offering a higher reward other than just watching it.
 

sorex

Expert
Licensed User
I'm having a look at this and all I seem to get is static interstitials?

Do I need a specific minimum api (I changed it from 9 to 14 for min & target) or something else ?

I used the chartboost adapter, not the inmobi one tho.

The rewarded video counter in admob increases so it's the right ID etc.
 

alimanam3386

Active Member
Licensed User
Hi,

How can we use this ad for test ( in physical device ) ? In AdView we have LoadAdWithTestDevice method but for RewardedVideoAd we dont have. how can we use it befor realse our application ?
 
Top