Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Other Unity ads not working in Android Mobile but in editor it works

Discussion in 'Unity Ads & User Acquisition' started by vayrex, Jun 23, 2022.

  1. vayrex

    vayrex

    Joined:
    Jun 15, 2022
    Posts:
    3
    Hi
    I'm using unity 2020.3.23f1 and I've imported (UnityAds Example App) from Package Manager.
    I've changed GameID and other things but still, it's not working in Android.
     
  2. SamOYUnity3D

    SamOYUnity3D

    Unity Technologies

    Joined:
    May 12, 2019
    Posts:
    603
    Please check the device log to see if there are any error occurs, you can also attach the device log here so we can check it.
     
  3. vayrex

    vayrex

    Joined:
    Jun 15, 2022
    Posts:
    3

    This is what happened...

    Code (CSharp):
    1. using System;
    2. using System.Collections;
    3. using UnityEngine.Advertisements;
    4. using UnityEngine;
    5.  
    6. public class UnityAdsManager : MonoBehaviour, IUnityAdsInitializationListener, IUnityAdsLoadListener, IUnityAdsShowListener
    7. {
    8.     public string GAME_ID = "4807220"; //replace with your gameID from dashboard. note: will be different for each platform.
    9.  
    10.     private const string BANNER_PLACEMENT = "Banner_Android";
    11.     private const string VIDEO_PLACEMENT = "Interstitial_Android";
    12.     private const string REWARDED_VIDEO_PLACEMENT = "Rewarded_Android";
    13.  
    14.     [SerializeField] private BannerPosition bannerPosition = BannerPosition.BOTTOM_CENTER;
    15.  
    16.     private bool testMode = true;
    17.     private bool showBanner = false;
    18.  
    19.     //utility wrappers for debuglog
    20.     public delegate void DebugEvent(string msg);
    21.     public static event DebugEvent OnDebugLog;
    22.  
    23.     public void Initialize()
    24.     {
    25.         if (Advertisement.isSupported)
    26.         {
    27.             DebugLog(Application.platform + " supported by Advertisement");
    28.         }
    29.         Advertisement.Initialize(GAME_ID, testMode, this);
    30.     }
    31.  
    32.     public void ToggleBanner()
    33.     {
    34.         showBanner = !showBanner;
    35.  
    36.         if (showBanner)
    37.         {
    38.             Advertisement.Banner.SetPosition(bannerPosition);
    39.             Advertisement.Banner.Show(BANNER_PLACEMENT);
    40.         }
    41.         else
    42.         {
    43.             Advertisement.Banner.Hide(false);
    44.         }
    45.     }
    46.  
    47.     public void LoadRewardedAd()
    48.     {
    49.         Advertisement.Load(REWARDED_VIDEO_PLACEMENT, this);
    50.     }
    51.  
    52.     public void ShowRewardedAd()
    53.     {
    54.         Advertisement.Show(REWARDED_VIDEO_PLACEMENT, this);
    55.     }
    56.  
    57.     public void LoadNonRewardedAd()
    58.     {
    59.         Advertisement.Load(VIDEO_PLACEMENT, this);
    60.     }
    61.  
    62.     public void ShowNonRewardedAd()
    63.     {
    64.         Advertisement.Show(VIDEO_PLACEMENT, this);
    65.     }
    66.  
    67.     #region Interface Implementations
    68.     public void OnInitializationComplete()
    69.     {
    70.         DebugLog("Init Success");
    71.     }
    72.  
    73.     public void OnInitializationFailed(UnityAdsInitializationError error, string message)
    74.     {
    75.         DebugLog($"Init Failed: [{error}]: {message}");
    76.     }
    77.  
    78.     public void OnUnityAdsAdLoaded(string placementId)
    79.     {
    80.         DebugLog($"Load Success: {placementId}");
    81.     }
    82.  
    83.     public void OnUnityAdsFailedToLoad(string placementId, UnityAdsLoadError error, string message)
    84.     {
    85.         DebugLog($"Load Failed: [{error}:{placementId}] {message}");
    86.     }
    87.  
    88.     public void OnUnityAdsShowFailure(string placementId, UnityAdsShowError error, string message)
    89.     {
    90.         DebugLog($"OnUnityAdsShowFailure: [{error}]: {message}");
    91.     }
    92.  
    93.     public void OnUnityAdsShowStart(string placementId)
    94.     {
    95.         DebugLog($"OnUnityAdsShowStart: {placementId}");
    96.     }
    97.  
    98.     public void OnUnityAdsShowClick(string placementId)
    99.     {
    100.         DebugLog($"OnUnityAdsShowClick: {placementId}");
    101.     }
    102.  
    103.     public void OnUnityAdsShowComplete(string placementId, UnityAdsShowCompletionState showCompletionState)
    104.     {
    105.         DebugLog($"OnUnityAdsShowComplete: [{showCompletionState}]: {placementId}");
    106.     }
    107.     #endregion
    108.  
    109.     public void OnGameIDFieldChanged(string newInput)
    110.     {
    111.         GAME_ID = newInput;
    112.     }
    113.  
    114.     public void ToggleTestMode(bool isOn)
    115.     {
    116.         testMode = isOn;
    117.     }
    118.  
    119.     //wrapper around debug.log to allow broadcasting log strings to the UI
    120.     void DebugLog(string msg)
    121.     {
    122.         OnDebugLog?.Invoke(msg);
    123.         Debug.Log(msg);
    124.     }
    125. }
    126.  
    and this is the codes...
     
  4. vayrex

    vayrex

    Joined:
    Jun 15, 2022
    Posts:
    3
    i think i fixed it now ♥
     
    SamOYUnity3D likes this.
  5. blacksmokey

    blacksmokey

    Joined:
    Dec 10, 2020
    Posts:
    1
    i know it's too late but can you tell me how did you fix it?