Admob的测试广告不会在我的任何测试设备上展示,但会记录它们已在Unity编辑器中加载。
我已经解决了android的依赖性,我将显示Manifest和AddCaller,并且我将显示Google Repository和Play服务SDK,但我不会看到任何错误,只是不会显示测试广告!
Android清单:
<?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>
AdScript:
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();
}
}
我希望显示测试标语和插页式广告,但什么也没发生。
并且在控制台中没有错误或警告,它表明虚拟对象已正确加载并显示。
答案 0 :(得分:1)
一个月前,我生成了第一个要在android上发布的应用程序,并且使用了Admob,并且没有任何错误,我认为一切都正确,在搜索互联网后,我没有找到解决方案,但是没有显示广告公告出现了2天,没有任何更改,如今我有3个应用程序,每次生成新应用程序时都会发生这种情况,请等待几天。