Freestar Ads Mediation Xamarin Android - freestar-archive/freestarcapital-SDK_documentation_Android GitHub Wiki
Freestar Ads Mediation provides support for Xamarin Android in C# by providing the necessary NuGet packages.
Note: More partners are being added, check sample app (below)Ad Provider | SDK Version | Ad Unit Types |
Admob | 20.6.0 | Fullscreen Interstitial & Rewarded, Banner 300x250, Banner 320x50 |
Google Ads Manager | 20.6.0 | Fullscreen Interstitial & Rewarded, Banner 300x250, Banner 320x50 |
Nimbus | 1.11.0 | Fullscreen Interstitial & Rewarded, Banner 300x250, Banner 320x50 |
TAM (Amazon) | 9.2.1 | Fullscreen Interstitial, Banner 300x250, Banner 320x50 |
Yahoo (Verizon) | 1.14.0 | Banner 300x250, Banner 320x50 |
• Before we begin, you must have a working Xamarin app running on an Android device. This document will not show how to create a Xamarin app for Android as that would be beyond the scope of Freestar Ads Mediation.
• Your Xamarin app must target MonoAndroid 12.0 or higher (Android API Level 31)
.
• Recommend Minimum Android API Level 21
In Visual Studio, INSTALL the following NuGet packages:Xamarin.Android.FreestarAds Xamarin.Android.FreestarAdmobAdapter Xamarin.Android.FreestarGamAdapter Xamarin.Android.FreestarNimbusAdapter Xamarin.Android.FreestarTamAdapter Xamarin.Android.FreestarGamAdapter Xamarin.Android.FreestarYahooAdapter Xamarin.Android.JetBrains.KotlinX_Serialization_Json Xamarin.AndroidX.Activity Xamarin.AndroidX.AppCompat Xamarin.AndroidX.Arch.Core.Common Xamarin.AndroidX.ConstraintLayout Xamarin.AndroidX.Lifecycle.Runtime Xamarin.AndroidX.Migration Xamarin.AndroidX.MultiDex Xamarin.Essentials Xamarin.GooglePlayServices.Ads Xamarin.Kotlin.StdLib.Jdk8 Xamarin.KotlinX.Coroutines.Android XamarinLibrary.Xamarin.Android.Squareup.Okhttp3.OkHttp Square.OkIO
Please add the following meta-data tags to the Application
tag of the AndroidManifest.xml
<meta-data android:name="com.google.android.gms.ads.APPLICATION_ID" android:value="ca-app-pub-3940256099942544~3347511713"/> <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/>
In the onCreate
of your starting Activity:
FreeStarAds.EnableTestAds(true); //set 'false' for production FreeStarAds.Init( [YOUR PARENT ACTIVITY], "XqjhRR"); //Use our test key
How to display full screen Interstitial ads:
First, implement the IInterstitialAdListener
interface.
Note: How to implement an interface in C# is beyond the scope of this document.
InterstitialAd interstitialAd = new InterstitialAd( [YOUR Parent Activity] , [YOUR IInterstitialAdListener] ); AdRequest adRequest = new AdRequest( [YOUR Parent Activity] ); interstitialAd.LoadAd(adRequest); //Note: you may pass an optional "placement" string as 2nd parameter if you wish.
When you receive OnInterstitialLoaded
from your IInterstitialAdListener
, you may show the ad:
interstitialAd.Show();
How to display full screen Rewarded ads:
First, implement the IRewardedAdListener
interface.
Note: How to implement an interface in C# is beyond the scope of this document.
RewardedAd rewardedAd = new RewardedAd ( [YOUR Parent Activity] , [YOUR IRewardedAdListener] ); AdRequest adRequest = new AdRequest( [YOUR Parent Activity] ); rewardedAd.LoadAd(adRequest); //Note: you may pass an optional "placement" string as 2nd parameter if you wish.
When you receive OnRewardedVideoLoaded
from your IRewardedAdListener
, you may show the ad:
/* Secret: Any arbitrary string you want to identify the reward by. e.g. "12345678". Cannot be blank. User Name: Can be the username of the user trying to obtain the reward; may be blank or null. Coin: The name of the type of reward. e.g. gold coin; may be blank or null. 30: The amount of the reward in string. may be blank or null. */ rewardedAd.ShowRewardAd("mysecret", "MyUsername", "Gold Coins", "30");
How to display Banner ads:
AdRequest adRequest = new AdRequest( [YOUR Parent Activity] ); BannerAd bannerAd = new BannerAd( [YOUR PARENT ACTIVITY] ); bannerAd.AdSize = AdSize.Banner32050; //For MREC size, use AdSize.MediumRectangle300250 bannerAd.SetBannerAdListener( [YOUR IBannerAdListener] ); bannerAd.LoadAd(adRequest); //Note: you may pass an optional "placement" string as 2nd parameter if you wish.
Next, you will receive OnBannerAdLoaded
of your IBannerAdListener
.
Here is an example implementation:
public void OnBannerAdLoaded(View bannerAdView, string placement) { BannerAd ad = (BannerAd)bannerAdView; if (ad.AdSize == AdSize.Banner32050) { YOUR_AdContainer.RemoveAllViews(); YOUR_AdContainer.AddView(bannerAdView); //FreeStar ad will be displayed now } }Please see the
Xamarin_Android_Sample
subfolder under this repo
Open using Microsoft Visual Studio