OnUserEarnedReward callback function does not work on android device

552 views
Skip to first unread message

Hasan Hüseyin Uğur

unread,
Mar 29, 2021, 10:34:58 AM3/29/21
to Google Mobile Ads SDK Developers
Hi, 

I'm having a problem with RewardedAd in Admob.
OnUserEarnedReward callback function does not work.
It works when I test it in Unity, but it doesn't work when I build and test it on an Android device.
Do you have any solution suggestions about this issue?
Unity: 2020.3.1f1
Admob: Google Mobile Ads Unity Plugin v5.4.0
Tested Android Device: Redmi Note 9 Pro (Android 10)

Example of the code I use to manage Admob;

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GoogleMobileAds.Api;


public class AdmobManager : MonoBehaviour
{
public static AdmobManager instance;

// Test IDs
public string InterstitialID = "ca-app-pub-3940256099942544/1033173712";
public string RewardedID = "ca-app-pub-3940256099942544/5224354917";

private InterstitialAd Interstitial;
private RewardedAd Rewarded;

private ButtonController _buttonController;

// Start is called before the first frame update
void Start()
{
MobileAds.Initialize(initStatus => { });

RequestInterstitial();
RequestRewardedAd();
DetectTheButtonController();
}

void Awake()
{
MakeSingleton();
}

#region Public Functions

public void ShowInterstitial()
{
if (Interstitial.IsLoaded())
{
Interstitial.Show();
}
}

public void ShowRewardedAd()
{
if (Rewarded.IsLoaded())
{
Rewarded.Show();
}
}

public void DetectTheButtonController()
{
if (_buttonController == null)
{
_buttonController = FindObjectOfType<ButtonController>();
}
}

#endregion

#region Private Functions

private void RequestInterstitial()
{
Interstitial = new InterstitialAd(InterstitialID);
Interstitial.OnAdClosed += Interstitial_OnAdClosed;
AdRequest request = new AdRequest.Builder().Build();
Interstitial.LoadAd(request);
}

private void Interstitial_OnAdClosed(object sender, System.EventArgs e)
{
RequestInterstitial();
}

private void RequestRewardedAd()
{
Rewarded = new RewardedAd(RewardedID);
Rewarded.OnUserEarnedReward += Rewarded_OnUserEarnedReward;
Rewarded.OnAdClosed += Rewarded_OnAdClosed;
AdRequest request = new AdRequest.Builder().Build();
Rewarded.LoadAd(request);
}

private void Rewarded_OnAdClosed(object sender, System.EventArgs e)
{
RequestRewardedAd();
}

private void Rewarded_OnUserEarnedReward(object sender, Reward e)
{
if (_buttonController != null)
{
_buttonController.GiveRewardedGold();
}
}

private void MakeSingleton()
{
if (instance != null)
{
Destroy(gameObject);
}
else
{
instance = this;
DontDestroyOnLoad(gameObject);
}
}
#endregion
}

Mobile Ads SDK Forum Advisor Prod

unread,
Mar 29, 2021, 1:40:37 PM3/29/21
to hasan.u...@gmail.com, google-adm...@googlegroups.com
HI Hasan,

Thank you for bringing this question ot our attention. Based on what you have said, it appears that you have been able to get it to work on the simulator in Unity and guessing that it works without any issue. But when loading it onto your phone then it does not work? If this is the case what are if any the errors that you are getting back when running the app on your phone. This would seem to be either an issue with the phone or how the app was loaded onto the phone. What phone are you testing on.

If you would also like, you can send over a sample app to us to look over and test on our side.

Regards,
Google Logo
William Pescherine
Mobile Ads SDK Team
 


ref:_00D1U1174p._5004Q2Eo3Wd:ref

Hasan Hüseyin Uğur

unread,
Mar 29, 2021, 7:00:17 PM3/29/21
to Google Mobile Ads SDK Developers
Hello William,

I solved the problem, problem was the gameobject.setActive(bool) i used in Admob script.
I figure it out we can't use UnityEngine special functions like setActive, RandomRange etc..
For the solution i used a public bool variable in Admob script then listen this variable in another script.

If there is a more logical way, I would appreciate it if you share it with me.

Thanks for for your attention.

29 Mart 2021 Pazartesi tarihinde saat 20:40:37 UTC+3 itibarıyla mobileadssdkforumadvisor şunları yazdı:

Mobile Ads SDK Forum Advisor Prod

unread,
Mar 29, 2021, 10:29:29 PM3/29/21
to hasan.u...@gmail.com, google-adm...@googlegroups.com

Hi Hasan,

Thank you for bringing this to us.

I work with William and will be assisting you today. For us to give insight on this, could you please provide us a sample app with your minimal implementation via Reply privately to author option or send it directly to mobileads...@gmail.com?

Regards,

Google Logo
Princess Pamela Pineda
Mobile Ads SDK Team
 


ref:_00D1U1174p._5004Q2Eo3Wd:ref
Reply all
Reply to author
Forward
0 new messages