Quantcast
Viewing all articles
Browse latest Browse all 1416

google admob rewarded videos onrewarded and onclosed event is not firing

i m trying reward user by watching video ad through admob . the adevents of onclosed and onrewarded is not calling but others such onvideo open,started,loaded are calling. i have checked will sample program given by google it is working fine. following is my code using System; using UnityEngine; using GoogleMobileAds; using GoogleMobileAds.Api; using UnityEngine.UI; // Example script showing how to invoke the Google Mobile Ads Unity plugin. public class adsc : MonoBehaviour { private BannerView bannerView; private InterstitialAd interstitial; private NativeExpressAdView nativeExpressAdView; private RewardBasedVideoAd rewardBasedVideo; //private float deltaTime = 0.0f; public GameObject button; public Text testxt; public Text rewardtxt; public void Start() { #if UNITY_ANDROID string appId = "ca-app-pub-3940256099942544~3347511713"; #elif UNITY_IPHONE string appId = "ca-app-pub-3940256099942544~1458002511"; #else string appId = "unexpected_platform"; #endif // Initialize the Google Mobile Ads SDK. MobileAds.Initialize(appId); // Get singleton reward based video ad reference. this.rewardBasedVideo = RewardBasedVideoAd.Instance; // RewardBasedVideoAd is a singleton, so handlers should only be registered once. // this.rewardBasedVideo.OnAdLoaded += this.HandleRewardBasedVideoLoaded; this.rewardBasedVideo.OnAdFailedToLoad += this.HandleRewardBasedVideoFailedToLoad; this.rewardBasedVideo.OnAdOpening += this.HandleRewardBasedVideoOpened; this.rewardBasedVideo.OnAdStarted += this.HandleRewardBasedVideoStarted; this.rewardBasedVideo.OnAdRewarded += this.HandleRewardBasedVideoRewarded; this.rewardBasedVideo.OnAdClosed += this.HandleRewardBasedVideoClosed; this.rewardBasedVideo.OnAdLeavingApplication += this.HandleRewardBasedVideoLeftApplication; } public void Update() { if(rewardBasedVideo.IsLoaded()) { button.gameObject.SetActive(true); } else { button.gameObject.SetActive(false); this.RequestRewardBasedVideo(); } } // Returns an ad request with custom ad targeting. private AdRequest CreateAdRequest() { return new AdRequest.Builder() .AddTestDevice(AdRequest.TestDeviceSimulator) .AddTestDevice("0123456789ABCDEF0123456789ABCDEF") .AddKeyword("game") .SetGender(Gender.Male) .SetBirthday(new DateTime(1985, 1, 1)) .TagForChildDirectedTreatment(false) .AddExtra("color_bg", "9B30FF") .Build(); } // calling functions public void onclickbutt () { if(rewardBasedVideo.IsLoaded()) { this.ShowRewardBasedVideo(); } else { this.RequestRewardBasedVideo(); } } private void RequestRewardBasedVideo() { #if UNITY_EDITOR string adUnitId = "unused"; #elif UNITY_ANDROID string adUnitId = "ca-app-pub-3940256099942544/5224354917"; #elif UNITY_IPHONE string adUnitId = "ca-app-pub-3940256099942544/1712485313"; #else string adUnitId = "unexpected_platform"; #endif this.rewardBasedVideo.LoadAd(this.CreateAdRequest(), adUnitId); } private void ShowRewardBasedVideo() { if (this.rewardBasedVideo.IsLoaded()) { this.rewardBasedVideo.Show(); } else { MonoBehaviour.print("Reward based video ad is not ready yet"); } } #region RewardBasedVideo callback handlers public void HandleRewardBasedVideoLoaded(object sender, EventArgs args) { testxt.text = "v loaded"; } public void HandleRewardBasedVideoFailedToLoad(object sender, AdFailedToLoadEventArgs args) { testxt.text = "v F loaded"; } public void HandleRewardBasedVideoOpened(object sender, EventArgs args) { testxt.text = "v opend"; } public void HandleRewardBasedVideoStarted(object sender, EventArgs args) { testxt.text = "v started"; } public void HandleRewardBasedVideoClosed(object sender, EventArgs args) { testxt.text = "v closed"; } public void HandleRewardBasedVideoRewarded(object sender, Reward args) { rewardtxt.text = "rewarded"; } public void HandleRewardBasedVideoLeftApplication(object sender, EventArgs args) { } #endregion }

Viewing all articles
Browse latest Browse all 1416

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>