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();
}
}
我希望显示一个测试横幅和一个测试插页式,但没有任何反应。
并且控制台中没有错误或警告,它表示假人已正确加载并显示。