Download

Tip: Easy Interstitial Admob Ads.

Just realized that UE 4.10 still has no support still interstitial ads.

Has anyone recently managed to get interstitials working? I will be working on the GameActivity.java file and will report back if I make any headway on my own.

**Update #1: my changes to the GameActivity.java file are being overwritten (regardless of ProGuard) and I am unsure how to prevent this from happening. I see no “original” file so honestly I am absolutely lost as to where or how the engine gets the original java file from. So unfortunately I cannot even begin to test the above code.

I’m imploring you, Epic, please update the tiiiiiiny bit of code required to show interstitial ads. Banner ads don’t cut it for my project. Not even a little. Until interstitials work, I can’t publish my product, which is extremely disheartening.**

As someone trying to make a living off their Unreal Engine Android game - I +1 this. Please, Epic added multiple admob ID support in 4.10 but there really needs to be more. I asked Ray Davis via twitch about expanded ad support and this was right when the analyics plugins were coming. He mentioned things were coming soon but that was the last I’ve heard or seen of any progress on this front.

I’ll see what I can do about getting this in but I can’t promise it will be in 4.11; it will need proper testing to make sure it doesn’t cause any other issues.

needle scratch

AdMob AppLovin Interstitial

Hello, Everyone

I was trying to add few more blueprints nodes exposing AdMob, and AppLovin Interstitial functionality.

In GameActivity.java if i add the following code inside AndroidThunkJava_ShowAdBanner(String AdMobAdUnitID, boolean bShowOnBottonOfScreen):


public void AndroidThunkJava_ShowAdBanner(String AdMobAdUnitID, boolean bShowOnBottonOfScreen)
	{
		Log.debug("In AndroidThunkJava_ShowAdBanner");
		Log.debug("AdID: " + AdMobAdUnitID);

		AndroidThunkJava_ShowAdMobInterstitial();
		//AndroidThunkJava_ShowAppLovinInterstitial();


//...code...//        

        }

where :


public void AndroidThunkJava_ShowAdMobInterstitial()
	{
		/** AdMob Interstitial Support */
		if(_activity.interstitialAd != null)
		{
		    _activity.runOnUiThread(new Runnable()
			{
			    @Override
				public void run()
				{
				    if(_activity.interstitialAd.isLoaded() == true)
					{
					    _activity.interstitialAd.show();
					}
				}
			});
		} 

	}

and


public void AndroidThunkJava_ShowAppLovinInterstitial()
	{
	    /**AppLovin Support  */
		if(AppLovinInterstitialAd.isAdReadyToDisplay(this))
		{
		    // An ad is available to display.  It's safe to call show.
		    AppLovinInterstitialAd.show(this);
		} 

	}

when i call the Show Ad Banner blueprint node, i either show AdMob or AppLovin interstitial ads(receiving test ads for both) together with AdMob banners without any problem.

I am trying to add few more blueprint nodes like Show Ad Banner in order to show Interstitial when i want regardless of showing banner, load them and check if they are loaded for both AdMob and AppLovin.

What i have done so far:

In the GameActivity.java:


public class GameActivity extends NativeActivity
{

//...code...//

/** AdMob and AppLovin Support */

	public void AndroidThunkJava_LoadAdMobInterstitial()
	{
	    interstitialAd.loadAd(request);
	}

	public void AndroidThunkJava_LoadAppLovinInterstitial()
	{
	    AppLovinSdk.getInstance(this).getAdService().preloadAd(AppLovinAdSize.INTERSTITIAL);
	}

	public boolean AndroidThunkJava_HasAdMobInterstitial()
	{
	    return _activity.interstitialAd.isLoaded();
	
	}

	public boolean AndroidThunkJava_HasApplovinInterstitial()
	{
	    return AppLovinInterstitialAd.isAdReadyToDisplay(this);
	
	}

	public void AndroidThunkJava_ShowAppLovinInterstitial()
	{
	    /**AppLovin Support  */
		if(AppLovinInterstitialAd.isAdReadyToDisplay(this))
		{
		    // An ad is available to display.  It's safe to call show.
		    AppLovinInterstitialAd.show(this);
		} 

	}


	public void AndroidThunkJava_ShowAdMobInterstitial()
	{
		/** AdMob Interstitial Support */
		if(_activity.interstitialAd != null)
		{
		    _activity.runOnUiThread(new Runnable()
			{
			    @Override
				public void run()
				{
				    if(_activity.interstitialAd.isLoaded() == true)
					{
					    _activity.interstitialAd.show();
					}
				}
			});
		} 

	}



//...code...//

}

In the AndroidJNI.cpp:



//...code...//

        // Admob Interstitials
	AndroidThunkJava_ShowAdMobInterstitial = FindMethod(Env, GoogleServicesClassID, "AndroidThunkJava_ShowAdMobInterstitial", "()V", bIsOptional);
	AndroidThunkJava_LoadAdMobInterstitial = FindMethod(Env, GoogleServicesClassID, "AndroidThunkJava_LoadAdMobInterstitial", "()V", bIsOptional);
	AndroidThunkJava_HasAdMobInterstitial = FindMethod(Env, GoogleServicesClassID, "AndroidThunkJava_HasAdMobInterstitial", "()V", bIsOptional);
	// AppLovin Interstitials
	AndroidThunkJava_ShowAppLovinInterstitial = FindMethod(Env, GoogleServicesClassID, "AndroidThunkJava_ShowAppLovinInterstitial", "()V", bIsOptional);
	AndroidThunkJava_LoadAppLovinInterstitial = FindMethod(Env, GoogleServicesClassID, "AndroidThunkJava_LoadAppLovinInterstitial", "()V", bIsOptional);
	AndroidThunkJava_HasAppLovinInterstitial = FindMethod(Env, GoogleServicesClassID, "AndroidThunkJava_HasAppLovinInterstitial", "()V", bIsOptional);

//...code...//

// Admob AppLovin Interstitials
jmethodID FJavaWrapper::AndroidThunkJava_ShowAdMobInterstitial;
jmethodID FJavaWrapper::AndroidThunkJava_LoadAdMobInterstitial;
jmethodID FJavaWrapper::AndroidThunkJava_HasAdMobInterstitial;

// Admob AppLovin Interstitials
jmethodID FJavaWrapper::AndroidThunkJava_ShowAppLovinInterstitial;
jmethodID FJavaWrapper::AndroidThunkJava_LoadAppLovinInterstitial;
jmethodID FJavaWrapper::AndroidThunkJava_HasAppLovinInterstitial;

//...code...//

//AdMob Interstitials
void AndroidThunkCpp_ShowAdMobInterstitial()
{
	if (JNIEnv* Env = FAndroidApplication::GetJavaEnv())
	{
		FJavaWrapper::CallVoidMethod(Env, FJavaWrapper::GoogleServicesThis, FJavaWrapper::AndroidThunkJava_ShowAdMobInterstitial);
	}
}

void AndroidThunkCpp_LoadAdMobInterstitial()
{
	if (JNIEnv* Env = FAndroidApplication::GetJavaEnv())
	{
		FJavaWrapper::CallVoidMethod(Env, FJavaWrapper::GoogleServicesThis, FJavaWrapper::AndroidThunkJava_LoadAdMobInterstitial);
	}
}

void AndroidThunkCpp_HasAdMobInterstitial()
{
	if (JNIEnv* Env = FAndroidApplication::GetJavaEnv())
	{
		FJavaWrapper::CallVoidMethod(Env, FJavaWrapper::GoogleServicesThis, FJavaWrapper::AndroidThunkJava_HasAdMobInterstitial);
	}
}


//AppLovin Interstitials
void AndroidThunkCpp_ShowAppLovinInterstitial()
{
	if (JNIEnv* Env = FAndroidApplication::GetJavaEnv())
	{
		FJavaWrapper::CallVoidMethod(Env, FJavaWrapper::GoogleServicesThis, FJavaWrapper::AndroidThunkJava_ShowAppLovinInterstitial);
	}
}

void AndroidThunkCpp_LoadAppLovinInterstitial()
{
	if (JNIEnv* Env = FAndroidApplication::GetJavaEnv())
	{
		FJavaWrapper::CallVoidMethod(Env, FJavaWrapper::GoogleServicesThis, FJavaWrapper::AndroidThunkJava_LoadAppLovinInterstitial);
	}
}

void AndroidThunkCpp_HasAppLovinInterstitial()
{
	if (JNIEnv* Env = FAndroidApplication::GetJavaEnv())
	{
		FJavaWrapper::CallVoidMethod(Env, FJavaWrapper::GoogleServicesThis, FJavaWrapper::AndroidThunkJava_HasAppLovinInterstitial);
	}
}




In the Android.JNI.h:




//...code...//

/ Admob AppLovin Interstitials
	static jmethodID AndroidThunkJava_ShowAdMobInterstitial;
	static jmethodID AndroidThunkJava_LoadAdMobInterstitial;
	static jmethodID AndroidThunkJava_HasAdMobInterstitial;
	static jmethodID AndroidThunkJava_ShowAppLovinInterstitial;
	static jmethodID AndroidThunkJava_LoadAppLovinInterstitial;
	static jmethodID AndroidThunkJava_HasAppLovinInterstitial;



In the KismetSystemLibrary.cpp:




//...code...//

/** AdMob Interstitial */

void UKismetSystemLibrary::ShowAdMobInterstitial()
{
	if (IAdvertisingProvider* Provider = FAdvertising::Get().GetDefaultProvider())
	{
		Provider->ShowAdMobInterstitial();
	}
}

void UKismetSystemLibrary::LoadAdMobInterstitial()
{
	if (IAdvertisingProvider* Provider = FAdvertising::Get().GetDefaultProvider())
	{
		Provider->LoadAdMobInterstitial();
	}
}

bool UKismetSystemLibrary::HasAdMobInterstitial()
{
	bool bHasAdMob = false;

	if (IAdvertisingProvider* Provider = FAdvertising::Get().GetDefaultProvider())
	{
		bHasAdMob = Provider->HasAdMobInterstitial();
	}

	return bHasAdMob;
}


/** AppLovin Interstitial */

void UKismetSystemLibrary::ShowAppLovinInterstitial()
{
	if (IAdvertisingProvider* Provider = FAdvertising::Get().GetDefaultProvider())
	{
		Provider->ShowAppLovinInterstitial();
	}
}

void UKismetSystemLibrary::LoadAppLovinInterstitial()
{
	if (IAdvertisingProvider* Provider = FAdvertising::Get().GetDefaultProvider())
	{
		Provider->LoadAppLovinInterstitial();
	}
}

bool UKismetSystemLibrary::HasAppLovinInterstitial()
{
	bool bHasAppLovin = false;

	if (IAdvertisingProvider* Provider = FAdvertising::Get().GetDefaultProvider())
	{
		bHasAppLovin = Provider->HasAppLovinInterstitial();
	}

	return bHasAppLovin;
}

//...code...//



In the KismetSystemLibrary.h




//...code...//

/**
	* Will show an Interstitial ad (AdMob on Android) on the top or bottom of screen, on top of the GL view (doesn't resize the view)
	* (Android only)
	*
	*/
	UFUNCTION(BlueprintCallable, Category = "Utilities|Platform")
	static void ShowAdMobInterstitial();

	/**
	* Will load an Interstitial ad (AdMob on Android) 
	* (Android only)
	*
	*/
	UFUNCTION(BlueprintCallable, Category = "Utilities|Platform")
	static void LoadAdMobInterstitial();

	/**
	* Will check if an Interstitial ad is available (AdMob on Android)
	* (Android only)
	*
	*/
	UFUNCTION(BlueprintCallable, Category = "Utilities|Platform")
	static bool HasAdMobInterstitial();

	/**
	* Will show an Interstitial ad (AppLovin on Android) on the top or bottom of screen, on top of the GL view (doesn't resize the view)
	* (Android only)
	*
	*/
	UFUNCTION(BlueprintCallable, Category = "Utilities|Platform")
	static void ShowAppLovinInterstitial();

	/**
	* Will load an Interstitial ad (AppLovin on Android)
	* (Android only)
	*
	*/
	UFUNCTION(BlueprintCallable, Category = "Utilities|Platform")
	static void LoadAppLovinInterstitial();

	/**
	* Will check if an Interstitial ad is available (AppLovin on Android)
	* (Android only)
	*
	*/
	UFUNCTION(BlueprintCallable, Category = "Utilities|Platform")
	static bool HasAppLovinInterstitial();

//...code...//



In the AndroidAdvertising.cpp:




//...code...//

void FAndroidAdvertisingProvider::ShowAdMobInterstitial()
{
	extern void AndroidThunkCpp_ShowAdMobInterstitial();
	AndroidThunkCpp_ShowAdMobInterstitial();
}

void FAndroidAdvertisingProvider::LoadAdMobInterstitial()
{
	extern void AndroidThunkCpp_LoadAdMobInterstitial();
	AndroidThunkCpp_LoadAdMobInterstitial();
}

bool FAndroidAdvertisingProvider::HasAdMobInterstitial()
{
	extern bool AndroidThunkCpp_HasAdMobInterstitial();
	bool bHasAdMob =AndroidThunkCpp_HasAdMobInterstitial();

	return bHasAdMob;
}

void FAndroidAdvertisingProvider::ShowAppLovinInterstitial()
{
	extern void AndroidThunkCpp_ShowAppLovinInterstitial();
	AndroidThunkCpp_ShowAppLovinInterstitial();
}

void FAndroidAdvertisingProvider::LoadAppLovinInterstitial()
{
	extern void AndroidThunkCpp_LoadAppLovinInterstitial();
	AndroidThunkCpp_LoadAppLovinInterstitial();
}

bool FAndroidAdvertisingProvider::HasAppLovinInterstitial()
{
	extern bool AndroidThunkCpp_HasAppLovinInterstitial();
	bool bHasAppLovin = AndroidThunkCpp_HasAppLovinInterstitial();
	return bHasAppLovin;

//...code...//



In the AdroidAdvertising.h:




//...code...//

        virtual void ShowAdMobInterstitial() override;
	virtual void LoadAdMobInterstitial() override;
	virtual bool HasAdMobInterstitial() override;

	virtual void ShowAppLovinInterstitial() override;
	virtual void LoadAppLovinInterstitial() override;
	virtual bool HasAppLovinInterstitial() override;



In the IAdvertisingProvider .h




//...code...//

        virtual void ShowAdMobInterstitial() = 0;
	virtual void LoadAdMobInterstitial() = 0;
	virtual bool HasAdMobInterstitial() = 0;

	virtual void ShowAppLovinInterstitial() = 0;
	virtual void LoadAppLovinInterstitial() = 0;
	virtual bool HasAppLovinInterstitial() = 0;



The new Blueprint nodes are exposed to Editor but they don’t seem to have any functionality.

Any feedback is highly appreciated.

Best,
Makis.

*UPDATE: 14/12/2015

AdColony Interstitial Videos seems to integrate great too, now we need to expose them too, to blueprints.

Hi Makis,

Add some FPlatformMisc::LowLevelOutputDebugStringf(TEXT(“Got to…”)); calls around and see if it is being called. This will write to the logcat with tag UE4.

Hi Chris,

In the AndroidJNI.cpp file i included:



//..code//

void AndroidThunkCpp_ShowAdMobInterstitial()
{
	if (JNIEnv* Env = FAndroidApplication::GetJavaEnv())
	{
		FJavaWrapper::CallVoidMethod(Env, FJavaWrapper::GoogleServicesThis, FJavaWrapper::AndroidThunkJava_ShowAdMobInterstitial);
		FPlatformMisc::LowLevelOutputDebugStringf(TEXT("ShowAdMobInterstitial called"));
	}
}



Do i need to add any header file?

I checked the logcat didn’t see it being called.

*UPDATE:

Hmm, just saw i did a mistake in the blueprint flow. The button i was clicking never called the new node.

I will check all new nodes again and see if they work.

If i want to implement new Event nodes, capturing when AdMob interstitial is clicked or closed for example or later, when a rewarded video was finished what will be the workflow?

I need to declare public native method in the GameActivity, call it anytime the AdMob Listener receives and event, and within that method, call the c++ method which broadcasts a delegate?

I am not sure how to call the c++ method from the java.

Or there is another workflow?

Take a look at any of the native* calls in GameActivity.java, for example nativeOnActivityResult()… this called from Java calls the C++ function Java_com_epicgames_ue4_GameActivity_nativeOnActivityResult() in AndroidJNI.cpp. This broadcasts to a delegate.

Hate to bump an old thread but it’s worth mentioning that you don’t need to comment out anything in the “public void AndroidThunkJava_HideAdBanner()” section.

I also did not comment out anything in “public void AndroidThunkJava_ShowAdBanner(String AdMobAdUnitID, boolean bShowOnBottonOfScreen)” and placed the following at the top of the method with a few changes:

changed…



if(_activity.interstitialAd != null)
{
	_activity.runOnUiThread(new Runnable()
	{
		@Override
		public void run()
		{
			if(_activity.interstitialAd.isLoaded() == true)
				_activity.interstitialAd.show();					
		}
	});

}


to the following…



		if(_activity.interstitialAd != null && !bShowOnBottonOfScreen)
		{
			_activity.runOnUiThread(new Runnable()
			{
				@Override
				public void run()
				{
					if(_activity.interstitialAd.isLoaded() == true)
						_activity.interstitialAd.show();					
				}
			});

			return;
		}


so now if I specify show ad on top it performs an interstitial, and if I choose show ad on bottom it displays a banner.

To do the opposite just change this…



		if(_activity.interstitialAd != null && !bShowOnBottonOfScreen)


to this…



		if(_activity.interstitialAd != null && bShowOnBottonOfScreen)


As mentioned before you don’t call hide ad for interstitial ads.

Your idea of using the bottom/top parameter is just great ! Thanks !
I’ll try that as soon as possible, anyone got feedback on blackscreens and intersticial loading problems some people had ?

How long has the black screen thing been an issue? It’s common to see black ads a day or even two after you first set them up.

Oh didn’t know, saved me some time not trying to correct that :slight_smile: thanks Guys for this great thread, it works perfectly !

does anyone know why i ve got this error
error: illegal start of expression
});
^

Did anyone else had this problem?

LogModuleManager:Warning: No filename provided for module AndroidAdvertising
LogModuleManager:Warning: ModuleManager: Unable to load module ‘AndroidAdvertising’ because the file ‘E:/Epic Games/4.12/Engine/Binaries/Win64/’ was not found.

It’s most likely extra brackets you left out when deleting the code mentioned. Check the line its giving that error in the output log and youll find it.

AdMob interstitial support will be in 4.14.

Fantastic :slight_smile:

Will that be the only upgrade regarding advertising support or can we expect some other new features as well?

AdMob interstitial ads will be the only advertising addition in 4.14 for Android.

Better late than never!