简体   繁体   English

Unity Admob广告无法在Android上运行

[英]Unity admob ads not working on android

I just launched my app called Dodge: the Game to android and iOS, when testing the ads were working on iOS. 当测试广告在iOS上正常运行时,我刚刚在Android和iOS上启动了名为Dodge:Game的应用。 When launching the game to both platforms there were no ads on android and in the Admob dashboard there are no requests. 在两个平台上都启动游戏时,Android上没有广告,而Admob仪表板中没有任何请求。 When there are for iOS. 适用于iOS的情况。

This is the code I am using to call ads: 这是我用来调用广告的代码:

using UnityEngine;
using UnityEngine.SceneManagement;
using GoogleMobileAds;
using GoogleMobileAds.Api;

public class Menu : MonoBehaviour {

private BannerView bannerView;

private void Awake()
{
    SetupAds();
}

void SetupAds()
{
    if (PlayerPrefs.HasKey("AdFree"))
        return;

    #if UNITY_IPHONE
        string appId = "ca-app-pub-9468963556585973~6866139959";
    #elif UNITY_ANDROID
        string appId = "ca-app-pub-9468963556585973~5324184926";
    #else 
        sting appId = "unexpected_platform";
    #endif

    // Initialize the Google Mobile Ads SDK.
    MobileAds.Initialize(appId);

    this.RequestBanner();

}

private void RequestBanner()
{
    #if UNITY_IPHONE
        string adUnitId = "ca-app-pub-9468963556585973/6704565848";
    #elif UNITY_ANDROID
        string adUnitId = "ca-app-pub-9468963556585973/7268247018";
    #else
        string adUnitId = "unexpected_platform";
    #endif

    // Create a 320x50 banner at the top of the screen.
    bannerView = new BannerView(adUnitId, AdSize.Banner, AdPosition.Bottom);

    // Create an empty ad request.
    AdRequest request = new AdRequest.Builder().Build();

    // Load the banner with the request.
    bannerView.LoadAd(request);
}

public void StartGame ()
{
    SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
}

public void DisableAds()
{
    Debug.Log("Ads disabled");
    if (PlayerPrefs.HasKey("AdFree"))
        print("Ads already removed");
    else{
        PlayerPrefs.SetInt("AdFree", 1);
        PlayerPrefs.Save();

        bannerView.Destroy();
    }
}
}

Just had to re-import the Google AdMob sdk. 只需重新导入Google AdMob sdk。 That was all. 就这些。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM