0

Admob 的测试广告不会显示在我的任何测试设备上,但会记录它们已加载到 Unity 编辑器中。

我已经解决了 android 依赖项,我将显示我的 Manifest 和 AddCaller,我有 Google Repository 和播放服务 SDK 我没有收到任何错误,它只是不会显示测试广告!

安卓清单:

<?xml version="1.0" encoding="utf-8"?>
<!--
This Google Mobile Ads plugin library manifest will get merged with your
application's manifest, adding the necessary activity and permissions
required for displaying ads. android:minSdkVersion="14"
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.google.unity.ads"
    android:versionName="1.0"
    android:versionCode="1">

  <!-- Required -->
  <uses-permission android:name="android.permission.INTERNET"/>

  <uses-sdk android:targetSdkVersion="19" />
  <application>
  <!-- Your AdMob App ID will look similar to this sample ID:
    ca-app-pub-3940256099942544~3347511713 -->
    <meta-data
    android:name="com.google.android.gms.ads.APPLICATION_ID"
    android:value="ca-app-pub-xxxxxxxxxx~xxxxxxx"/>
  </application>
</manifest>

广告脚本:

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

public class AddScript : MonoBehaviour
{
    private string AppID = "ca-app-pub-xxxxxxxx~xxxxxxxx";

    private BannerView bannerAD;
    public InterstitialAd interAD;

    public int addTick;

    // Start is called before the first frame update
    void Start()
    {
        string appId = AppID;

        //Initialize Ads SDK
        MobileAds.Initialize(appId);
        RequestInterstitial();
        RequestBanner();
    }

    private void OnLevelWasLoaded(int level)
    {
        if (level == 2)
        {
            ShowInterstitial();
        }

        if(level == 1)
       {
            bannerAD.Show();
       }
    }

    private void RequestInterstitial()
    {
#if UNITY_ANDROID
        string adUnitId = "ca-app-pub-3940256099942544/1033173712";
#elif UNITY_IPHONE
        string adUnitId = "ca-app-pub-3940256099942544/4411468910";
#else
        string adUnitId = "unexpected_platform";
#endif

        // Initialize an InterstitialAd.
        this.interAD = new InterstitialAd(adUnitId);
        // Create an empty ad request.
        AdRequest request = new AdRequest.Builder().AddTestDevice("xxxxxxxxxxxx").Build();

        // Called when an ad request has successfully loaded.
        interAD.OnAdLoaded += HandleOnAdLoaded;
        // Called when an ad request failed to load.
        interAD.OnAdFailedToLoad += HandleOnAdFailedToLoad;

        // Load the interstitial with the request.
        this.interAD.LoadAd(request);
    }

    private void ShowInterstitial()
    {
        if (this.interAD.IsLoaded())
        {
            this.interAD.Show();
        }
        else
        {
            MonoBehaviour.print("Interstitial is not ready yet");
        }
    }


    private void RequestBanner()
    {
        string adUnitId = "ca-app-pub-3940256099942544/6300978111";

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

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

        // Load the banner with the request.
        bannerAD.LoadAd(request);

    }

    public void HandleOnAdLoaded(object sender, EventArgs args)
    {
        MonoBehaviour.print("HandleAdLoaded event received");
    }

    public void HandleOnAdFailedToLoad(object sender, AdFailedToLoadEventArgs args)
    {
        MonoBehaviour.print("HandleFailedToReceiveAd event received with message: " + args.Message);
    RequestInterstitial();
    }
}

我希望显示一个测试横幅和一个测试插页式,但没有任何反应。

并且控制台中没有错误或警告,它表示假人已正确加载并显示。

4

1 回答 1

1

一个月前,我生成了我的第一个应用程序在 android 上发布,我使用了 Admob,我没有错误,我认为一切都是正确的,在搜索互联网后我没有找到解决方案,广告没有显示,2 天后公告出现了,没有任何改变,现在我有 3 个应用程序,每次生成新应用程序时都会发生这种情况,请等待几天。

于 2019-05-24T19:37:44.327 回答