So I implemented Google AdMob in my Unity game and when I built and run it on my android devie, the game won't start up.
I didn't quite understand what I need to do here:
What do I need to replace th andorid:name APPLICATION_ID with?
the android:value should be my admob ID but what should the android:name be?
I also followed the Google AdMob tutorial here: https://developers.google.com/admob/unity/start
Here is the AdManager code:
Something weird is that I didn't get any respond from these handlers.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GoogleMobileAds.Api;
using System;
public class GoogleMobileAdsManager : MonoBehaviour
{
private BannerView bannerView;
// Start is called before the first frame update
public void Start()
{
Debug.Log("STARTED");
this.RequestBanner();
}
private void RequestBanner()
{
#if UNITY_ANDROID
string adUnitId = "ID HERE";
//Test ad
#else
string adUnitId = "unexpected_platform";
#endif
bannerView = new BannerView(adUnitId, AdSize.Banner, AdPosition.Top);
// Called when an ad request has successfully loaded.
bannerView.OnAdLoaded += HandleOnAdLoaded;
// Called when an ad request failed to load.
bannerView.OnAdFailedToLoad += HandleOnAdFailedToLoad;
// Called when an ad is clicked.
bannerView.OnAdOpening += HandleOnAdOpened;
// Called when the user returned from the app after an ad click.
bannerView.OnAdClosed += HandleOnAdClosed;
// Called when the ad click caused the user to leave the application.
bannerView.OnAdLeavingApplication += HandleOnAdLeavingApplication;
// Create an empty ad request.
AdRequest request = new AdRequest.Builder().Build();
// Load the banner with the request.
bannerView.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);
}
public void HandleOnAdOpened(object sender, EventArgs args)
{
MonoBehaviour.print("HandleAdOpened event received");
}
public void HandleOnAdClosed(object sender, EventArgs args)
{
MonoBehaviour.print("HandleAdClosed event received");
}
public void HandleOnAdLeavingApplication(object sender, EventArgs args)
{
MonoBehaviour.print("HandleAdLeavingApplication event received");
}
}
Any idea why isn't it working? Did I do something wrong?
EDIT:
Solved it. Make sure here
`android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="YOUR_ADMOB_APP_ID"/>`
you fill your AdMob app ID in android:value and leave android:name as it is.
↧