Unity - Interstitial Ads dosent work

114 views
Skip to first unread message

Alex S

unread,
Jul 21, 2014, 3:22:47 PM7/21/14
to google-adm...@googlegroups.com
Hi!

I try to get the Intersitial ads to work, but they dosent show. In Unity i get the msg that the ad is loaded and show is called but on my phone the ads dosent show.

my code to call+load ads is:
using UnityEngine;
using System.Collections;
using System;
using GoogleMobileAds;
using GoogleMobileAds.Api;

public class ADSC : MonoBehaviour {

public static InterstitialAd interstitial;
void Start(){
RequestInterstitial();
ShowInterstitial();
}
private void RequestInterstitial()
{
#if UNITY_EDITOR
string adUnitId = "ca-app-pub-*****/*****";
#elif UNITY_ANDROID
string adUnitId = "ca-app-pub-*****/*****";
#elif UNITY_IPHONE
string adUnitId = "ca-app-pub-*****/*****";
#else
string adUnitId = "ca-app-pub-*****/*****";
#endif
interstitial = new InterstitialAd(adUnitId);
interstitial.LoadAd(createAdRequest());
}
private AdRequest createAdRequest()
{ return new AdRequest.Builder ().Build();            }
private void ShowInterstitial()
{
if (interstitial.IsLoaded())
{
interstitial.Show();
print("Ad loaded+show called");
}
else
{
print("Interstitial is not ready yet.");
}
}
}
and my AndroidManifest.xml is:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="de.Project" android:theme="@android:style/Theme.NoTitleBar" android:versionName="1.0" android:versionCode="1" android:installLocation="preferExternal">
  <supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" />
  <application android:icon="@drawable/app_icon" android:label="@string/app_name" android:debuggable="false">
    <!-- meta-data tag for Google Play services -->
    <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/>
    <activity android:name="com.unity3d.player.UnityPlayerNativeActivity" android:label="@string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" >
      <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
      <meta-data android:name="android.app.lib_name" android:value="unity" />
    </activity>

    <!-- Google Mobile Ads Activity -->
 <activity android:name="com.google.android.gms.ads.AdActivity"
              android:label="@string/app_name"
              android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
    
    </activity>
  </application>
  <uses-sdk android:minSdkVersion="9" android:targetSdkVersion="20" />
  <uses-permission android:name="android.permission.INTERNET"/>
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
  <uses-feature android:glEsVersion="0x00020000" />
</manifest>

In Unity i get the msg "Ad loaded+show called".
I did import the plugin and the google-play-services_lib ordner to Plugins/Android. Then i did build the project to get a "new" AndroidManifest.xml from -project/Temp/StagingArea. This one i modified like described in Readme.

Alex :)

Eric Leichtenschlag

unread,
Jul 22, 2014, 5:58:19 PM7/22/14
to google-adm...@googlegroups.com
Hi Alex,

I'm a little surprised that interstitial.IsLoaded() returns true for you with this code. I double checked the codebase and I don't see an obvious bug in the method.

In your start method, you're calling ShowInterstitial() immediately after RequestInterstitial(), but it can take a second or two for an ad to be ready. So the interstitial isn't actually ready to be shown. You can listen for the adloaded event to know when the interstitial is loaded, but in practice using isLoaded() is the recommended approach.

Thanks,
Eric

Alex S

unread,
Jul 23, 2014, 7:52:44 AM7/23/14
to google-adm...@googlegroups.com
Ah perfect :-)  Now i wait 2s before showing the Ads on start and then i handle it by requesting it in the scene before i want to display it. 

Thanks,
Alex :)
Reply all
Reply to author
Forward
0 new messages