Freestar Ads Mediation Xamarin Android
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
If your game or app is officially under the Google Play Families program, Freestar provides such support:
FreeStarAds.setGoogleFamilyPolicyMode( GoogleFamilyPolicyMode.app, true); //If your app is designed only for children //FreeStarAds.setGoogleFamilyPolicyMode( GoogleFamilyPolicyMode.mixed, false); //If your app is designed for families with children FreeStarAds.init(...);
If your app is not officially under the Google Play Families program, then you do not need to set the Google Family Policy mode.
/** * Only set Google Families Policy Mode if your app is required to comply with Google Play’s * Families Policy program. * * @param googleFamilyPolicyMode app: the app is child-directed and will not receive * personalize or contextual ads. * mixed: the app is directed at mixed audiences. * none: (default) the app is not required to comply with Google * Play's Family Policy * * @param onlyNonPersonalizedAds true: if 'mixed' mode, then only personalized or contextual ads * may be served. * false: if 'mixed' mode, then personalized or contextual ads * may be served. * note: if 'app' mode, then personalized or contextual ads * may not be served regardless of this parameter. */ public static void setGoogleFamilyPolicyMode(GoogleFamilyPolicyMode googleFamilyPolicyMode, boolean onlyNonPersonalizedAds)
If you use the above code, then our SDK will automatically and internally utilize Google methods:
setTagForChildDirectedTreatment( true )
setMaxAdContentRating( Rated_G )
Freestar SDK is GDPR compliant. In order for your users to be able to receive any ad fills in GDPR-affected countries, you, as a publisher, will need to implement a 3rd party Consent Management Platform (CMP). Freestar SDK will automatically detect user interactions with the CMP and act accordingly. Please see our Freestar GDPR Frequently Asked Questions for complete details and our recommended list of CMP service providers.
For Android, please use our test key XqjhRR for all your testing runs and enable test mode true. You will usually get 100% fill on all ad units. It is not recommended to use your production key for testing runs as that is strictly prohibited by our partners and bad things may happen to us on the business side of things.
Do not forget to uninstall and re-install your app when changing keys on your device.
When you are satisfied with your testing, please make a release build with your production key, and turn test mode off. Publish to store.
Are your automated tests failing after integrating Freestar Mediation Ads into your mobile application or game? Are you not sure it could be due to Freestar or something else? We have a feature called Automated Test Mode where you can run your automated tests to bypass Freestar or run Freestar in 'Limited Mediation' mode without making drastic changes to your code:
In your automated test suite code, before FreeStarAds.init is called:
FreeStarAds.setAutomatedTestMode( FreeStarAds.AutomatedTestMode.BYPASS_ALL_ADS )
//OR
FreeStarAds.setAutomatedTestMode( FreeStarAds.AutomatedTestMode.LIMITED_MEDIATION ) //only runs AdMob & GAM
Again, this is only for your automated tests and not for production use.
Final note when creating your release build: if you use proguard or minify, please add our proguard rules to your app proguard file.