Search Unity

Callback not working on Android

Discussion in 'Unity Ads' started by Gabrihellbarbosa, Sep 30, 2019.

  1. Gabrihellbarbosa

    Gabrihellbarbosa

    Joined:
    Jan 6, 2015
    Posts:
    2
    Hey, guys!

    I am implementing Unity Ads in a project. I put a banner at the beginning and a reward video. Unity testing works correctly, but on Android, video callbacks are not called. The video plays, but after closing, nothing happens in the game. After closing the video, a respawn function is called on the player. On Unity it works, but not on Android. Does anyone know how to solve and what may be causing it?

    Here is the script associated directly on the button. I did similar to the one described in the implementation guide:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5. using UnityEngine.Advertisements;
    6.  
    7. public class RewardedAdsButton : MonoBehaviour, IUnityAdsListener
    8. {
    9.  
    10.     Button myButton;
    11.     public string myPlacementId = "rewardedVideo";
    12.  
    13.     public PlayerHealth player;
    14.  
    15.     // Start is called before the first frame update
    16.     void Start()
    17.     {
    18.         myButton = GetComponent<Button>();
    19.  
    20.         // Set interactivity to be dependent on the Placement’s status:
    21.         myButton.interactable = Advertisement.IsReady(myPlacementId);
    22.  
    23.         // Map the ShowRewardedVideo function to the button’s click listener:
    24.         if (myButton) myButton.onClick.AddListener(ShowRewardedVideo);
    25.  
    26.         // Initialize the Ads listener and service:
    27.         Advertisement.AddListener(this);
    28.         Advertisement.Initialize("3307084", true);
    29.     }
    30.  
    31.     void ShowRewardedVideo()
    32.     {
    33.         Advertisement.Show(myPlacementId);
    34.     }
    35.  
    36.     // Implement IUnityAdsListener interface methods:
    37.     public void OnUnityAdsReady(string placementId)
    38.     {
    39.         // If the ready Placement is rewarded, activate the button:
    40.         if (placementId == myPlacementId)
    41.         {
    42.             myButton.interactable = true;
    43.         }
    44.     }
    45.  
    46.     public void OnUnityAdsDidFinish(string placementId, ShowResult showResult)
    47.     {
    48.        
    49.  
    50.         // Define conditional logic for each ad completion status:
    51.         if (showResult == ShowResult.Finished)
    52.         {
    53.             player.Respawn(100);
    54.         }
    55.         else if (showResult == ShowResult.Skipped)
    56.         {
    57.             // Do not reward the user for skipping the ad.
    58.         }
    59.         else if (showResult == ShowResult.Failed)
    60.         {
    61.             Debug.LogWarning("The ad did not finish due to an error.");
    62.         }
    63.     }
    64.  
    65.     public void OnUnityAdsDidError(string message)
    66.     {
    67.         // Log the error.
    68.     }
    69.  
    70.     public void OnUnityAdsDidStart(string placementId)
    71.     {
    72.         // Optional actions to take when the end-users triggers an ad.
    73.     }
    74. }
    75.  
     
  2. Gabrihellbarbosa

    Gabrihellbarbosa

    Joined:
    Jan 6, 2015
    Posts:
    2
    Ok. After some testing, I was able to resolve just by disabling and activating Ads in the Services window.