- Home /
Admob banner is not showing
I have a game that I am trying to add ad banners to it, I have add the necessary manifest and code to do so but when i run it nothing shows up and I have no errors. Please help.
ad code
using UnityEngine;
using System.Collections;
using GooglePlayGames;
using UnityEngine.SocialPlatforms;
public class Ads : MonoBehaviour {
private const string AD_Unit_ID = "ca-app-pub-416510********39/3648529009";
private AdMobPlugin admob;
public void Awake()
{
DontDestroyOnLoad (this);
}
void Start () {
admob = GetComponent<AdMobPlugin> ();
admob.CreateBanner (AD_Unit_ID, AdMobPlugin.AdSize.SMART_BANNER, true,"",false);
admob.RequestAd ();
admob.ShowBanner ();
}
}
AdMobPlugin
using System;
using UnityEngine;
public sealed class AdMobPlugin : MonoBehaviour {
private const string CLASS_NAME = "com.nabrozidhs.admob.AdMob";
private const string CALL_SHOW_BANNER = "showBanner";
private const string CALL_HIDE_BANNER = "hideBanner";
private const string CALL_SHOW_INSTERTITIAL = "showInterstitial";
private const string CALL_REQUEST_AD = "requestAd";
private const string CALL_REQUEST_INTERSTITIAL = "requestInterstitial";
public enum AdSize {BANNER, MEDIUM_RECTANGLE, FULL_BANNER, LEADERBOARD, SMART_BANNER};
public static event Action AdClosed = delegate{};
public static event Action AdFailedToLoad = delegate{};
public static event Action AdLeftApplication = delegate{};
public static event Action AdLoaded = delegate{};
public static event Action AdOpened = delegate{};
public static event Action InterstitialClosed = delegate{};
public static event Action InterstitialFailedToLoad = delegate{};
public static event Action InterstitialLeftApplication = delegate{};
public static event Action InterstitialLoaded = delegate{};
public static event Action InterstitialOpened = delegate{};
#if UNITY_ANDROID && !UNITY_EDITOR
private AndroidJavaObject plugin;
#endif
/// <summary>
/// Bind this instance.
/// </summary>
public void CreateBanner(string adUnitId, AdSize adSize, bool isTopPosition=true, string interstitialId="", bool isTestDevice=false) {
if (String.IsNullOrEmpty(interstitialId)) {
interstitialId = "";
}
#if UNITY_ANDROID && !UNITY_EDITOR
plugin = new AndroidJavaObject(
CLASS_NAME,
new AndroidJavaClass("com.unity3d.player.UnityPlayer")
.GetStatic<AndroidJavaObject>("currentActivity"),
adUnitId,
adSize.ToString(),
isTopPosition,
interstitialId,
gameObject.name,
isTestDevice);
#endif
}
/// <summary>
/// Requests a banner ad. This method should be called
/// after we have created a banner.
/// </summary>
public void RequestAd() {
#if UNITY_ANDROID && !UNITY_EDITOR
if (plugin != null) {
plugin.Call(CALL_REQUEST_AD, new object[0]);
}
#endif
}
/// <summary>
/// Requests an interstitial ad.
/// </summary>
public void RequestInterstitial() {
#if UNITY_ANDROID && !UNITY_EDITOR
if (plugin != null) {
plugin.Call(CALL_REQUEST_INTERSTITIAL, new object[0]);
}
#endif
}
/// <summary>
/// Shows the banner to the user.
/// </summary>
public void ShowBanner() {
#if UNITY_ANDROID && !UNITY_EDITOR
if (plugin != null) {
plugin.Call(CALL_SHOW_BANNER, new object[0]);
}
#endif
}
/// <summary>
/// Hides the banner from the user.
/// </summary>
public void HideBanner() {
#if UNITY_ANDROID && !UNITY_EDITOR
if (plugin != null) {
plugin.Call(CALL_HIDE_BANNER, new object[0]);
}
#endif
}
/// <summary>
/// Shows the interstitial ad to the user.
/// </summary>
public void ShowInterstitial() {
#if UNITY_ANDROID && !UNITY_EDITOR
if (plugin != null) {
plugin.Call(CALL_SHOW_INSTERTITIAL, new object[0]);
}
#endif
}
public void OnAdClosed() {
AdClosed();
}
public void OnAdFailedToLoad() {
AdFailedToLoad();
}
public void OnAdLeftApplication() {
AdLeftApplication();
}
public void OnAdLoaded() {
AdLoaded();
}
public void OnAdOpened() {
AdOpened();
}
Android Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="preferExternal" package="com.example.admobtest" android:versionName="1.0" android:versionCode="1">
<supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application android:icon="@drawable/app_icon" android:label="@string/app_name" android:debuggable="true">
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" /> <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
<activity android:name="com.unity3d.player.UnityPlayerProxyActivity" 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" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.unity3d.player.UnityPlayerActivity" android:label="@string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
</activity>
<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>
<activity android:name="com.unity3d.player.VideoPlayer" android:label="@string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
</activity>
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />
<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>
<activity android:name="com.facebook.unity.FBUnityLoginActivity" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen">
</activity>
<activity android:name="com.facebook.LoginActivity" android:configChanges="keyboardHidden|orientation" android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen">
</activity>
<activity android:name="com.facebook.unity.FBUnityDeepLinkingActivity" android:exported="true">
</activity>
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="\ 694764773973338
" />
</application>
<uses-feature android:glEsVersion="0x00020000" />
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="19" />
</manifest>
Comment
Answer by nishant_talaviya · Jan 07, 2015 at 09:24 PM
There is problem in AD_Unit_ID. please verify the AD_Unit_ID. it does not contain * sign
Your answer
Follow this Question
Related Questions
Unity Android READ_PHONE_STATE permission 0 Answers
How to place Adv Vertically 1 Answer
Reloading the scene causes ads to reload. Is this ok ? 3 Answers
Missing AdActivity with android:configChanges in AndroidManifest.xml 0 Answers
After updating android sdk getting error “Package name is not a valid java package name” 0 Answers