public void BuildInterstitial(){ failedLoading = false; interstitial = new InterstitialAd(adUnitID); // Events interstitial.OnAdClosed += HandleInterstitialClosed; interstitial.OnAdFailedToLoad += HandleInterstitialFailedToLoad; interstitial.OnAdLeavingApplication += HandleLeftApplication; interstitial.OnAdLoaded += HandleLoaded; interstitial.OnAdOpening += HandleOpened; // AdRequest AdRequest.Builder builder = new AdRequest.Builder (); if (useEmulatorAsATestDevice) { builder.AddTestDevice(AdRequest.TestDeviceSimulator); } if (testDeviceIDs != null && testDeviceIDs.Length > 0) { foreach(string testDeviceID in testDeviceIDs){ builder.AddTestDevice(testDeviceID); } } if (keywords != null && keywords.Length > 0) { foreach (string keyword in keywords) { builder.AddKeyword (keyword); } } if (gender.HasValue) { builder.SetGender (gender.Value); } if (childDirectedTreatment.HasValue) { builder.TagForChildDirectedTreatment (childDirectedTreatment.Value); } AdRequest request = builder.Build(); interstitial.LoadAd(request); }
private AdRequest getAdRequest(){ // Creating the request builder AdRequest.Builder requestBuilder = new AdRequest.Builder(); // Test devices if(useEmulatorAsATestDevice){ requestBuilder.AddTestDevice(AdRequest.TestDeviceSimulator); } foreach(string deviceID in testDevices){ if(!string.IsNullOrEmpty(deviceID)){ requestBuilder.AddTestDevice(deviceID); } } // Keywords string[] words = keywords.Split(','); foreach(string word in words){ if(word.Trim() != string.Empty) requestBuilder.AddKeyword(word.Trim()); } // Gender if(gender != Gender.Unknown) requestBuilder.SetGender(gender); // Tag for child directed treatment if (tagForChildDirectedTreatment != TagForChildDirectedTreatment.NotTagged) { requestBuilder.TagForChildDirectedTreatment (tagForChildDirectedTreatment == TagForChildDirectedTreatment.True); } return requestBuilder.Build(); }