AdRequest GetRequest(Dictionary <string, string> advertisingTargetInfo) { var request = new AdRequest.Builder(); request.AddTestDevice(AdRequest.DeviceIdEmulator); request.AddTestDevice("260661DE96DFEDE845160916AD01F3CA"); //samsung tablet //Gender var gender = Gender.Unknown; if (advertisingTargetInfo.ContainsKey(AdKeyGender)) { gender = advertisingTargetInfo[AdKeyGender].Equals("female", StringComparison.InvariantCultureIgnoreCase) ? Gender.Female : Gender.Male; request.SetGender((int)gender); } //Location var location = RealmServices.GetLastUserLocation(); if (location != null) { var loc = new Android.Locations.Location(""); loc.Latitude = location.Latitude; loc.Longitude = location.Longitude; loc.Accuracy = 1; request.SetLocation(loc); } //Birthday if (advertisingTargetInfo.ContainsKey(AdKeyBirthday)) { var birthday = DateTime.ParseExact(advertisingTargetInfo[AdKeyBirthday], "MM/dd/yyyy", null); var bith = new Java.Util.Date(birthday.Year, birthday.Month, birthday.Day); request.SetBirthday(bith); } return(request.Build()); }
{ var bannerView = new BannerView(AdSizeCons.SmartBannerPortrait); bannerView.AdUnitID = "ca-app-pub-4252799872870196/8180596755"; bannerView.RootViewController = this; bannerView.ReceiveAdFailed += (sender, e) => { Console.Write(e.Error.LocalizedDescription); AdViewSuperViewHeightConstaint.Constant = 0; }; bannerView.AdReceived += (sender, e) => { AdViewSuperViewHeightConstaint.Constant = AddViewSuperviewHeight; }; AdViewSuperView.AddSubview(bannerView); var request = GetRequest(advertisingTargetInfo); bannerView.LoadRequest(request); } Request GetRequest(Dictionary<string, string> advertisingTargetInfo) { var request = Request.GetDefaultRequest(); request.TestDevices = new string[] { Request.SimulatorId.ToString() }; //Gender var gender = Gender.Unknown; if (advertisingTargetInfo.ContainsKey(AdKeyGender)) gender = advertisingTargetInfo[AdKeyGender].Equals("female", StringComparison.InvariantCultureIgnoreCase) ? Gender.Female : Gender.Male; request.Gender = gender; //Location var location = RealmServices.GetLastUserLocation(); if (location != null) request.SetLocation((nfloat)location.Latitude, (nfloat)location.Longitude, 1); //Birthday if (advertisingTargetInfo.ContainsKey(AdKeyBirthday)) { var birthday = DateTime.ParseExact(advertisingTargetInfo[AdKeyBirthday], "MM/dd/yyyy",null); request.SetBirthday(birthday.Month, birthday.Day, birthday.Year); } //todo Keywords return request; }