Home > Blockchain >  Admob multiple problems
Admob multiple problems

Time:04-02

i have a problem about admob. To start, i added the code and setting for test ad. Small banner appear on top but when i try to test the interstitial, the interstitial ad (on button click) appear for half of a second and disappear. I tried everything but nothing i can do.

Here is the code:

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

public class AdManager : MonoBehaviour
{
private BannerView bannerView;
private InterstitialAd interstitial;

[System.Obsolete]
void Start()
{
    // Initialize the Google Mobile Ads SDK.
    MobileAds.Initialize(initStatus => { });

    this.RequestBanner();
    this.RequestInterstitial();

}

private void RequestBanner()
{
#if UNITY_ANDROID
    string adUnitId = "ca-app-pub-3940256099942544~3347511713";
#elif UNITY_IPHONE
        string adUnitId = "";
#else
        string adUnitId = "unexpected_platform";
#endif

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

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

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


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

    // Initialize an InterstitialAd.
    this.interstitial = new InterstitialAd(adUnitId);
    // Create an empty ad request.
    AdRequest request = new AdRequest.Builder().Build();
    // Load the interstitial with the request.
    this.interstitial.LoadAd(request);
}

public void Show_InterstitialAd()
{
    if (this.interstitial.IsLoaded())
    {
        this.interstitial.Show();
    }
    else
    {
        print("Ad is not show!");
    }
}

}

This is the setup in unity: enter image description here enter image description here

When i click on the button interstitial appear for 0.5 seconds and than disappear. Now im trying almost everything i see on youtube but nothing work and as im new into it, i really but really dont know what can i do.

Also another problem, i'm trying to test my app on my own mobile device and the banner on top appear on unity test but nothing when i install the apk on my device. I added test device to admob, nothing. Tried to take the shake method to show banner, nothing. This admob thing is driving me crazy.

Need help!!

Thank you!!!

CodePudding user response:

Well i finally found how to solve it. There is the way to do it. If your application dont show ad, remember that you have to create a empty gameObject and drop the code of your admob request and show into it. So whatever the banner you want, remember you need to "request and load ad" and also "show" it. Google have a code name "helloworld" on github that have the working function.

this youtube video is what helped me: https://youtu.be/e-q_CPfu0M0

CodePudding user response:

Good to know, thanks for answer. Unity ADs in hell these days, from 4.0.x and above. :(

  • Related