protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.View> e) { base.OnElementChanged(e); var adLoader = new AdLoader.Builder(Context, AppConfig.ADMOB_NATIVE_ADS_ID); var listener = new UnifiedNativeAdLoadedListener(); listener.OnNativeAdLoaded += (s, ad) => { // Load ad Completed try { ButtonColor = (e.NewElement as AdmobSmallNativeAdsView).ButtonColor.ToAndroid(); nativeAd = ad; var root = new UnifiedNativeAdView(Context); var inflater = (LayoutInflater)Context.GetSystemService(Context.LayoutInflaterService); var nativeAdView = (UnifiedNativeAdView)inflater.Inflate(Resource.Layout.gnt_small_template_view, root); populateUnifiedNativeAdView(ad, nativeAdView); SetNativeControl(nativeAdView); } catch { } }; adLoader.ForUnifiedNativeAd(listener); var requestBuilder = new AdRequest.Builder(); adLoader.Build().LoadAd(requestBuilder.Build()); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); Xamarin.Essentials.Platform.Init(this, savedInstanceState); SetContentView(Resource.Layout.activity_main); Android.Support.V7.Widget.Toolbar toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar); SetSupportActionBar(toolbar); ///Init ManagerAds adsMgr = new AdsManager(ApplicationContext); txtStatusInter = FindViewById <TextView>(Resource.Id.txtStateInterstitial); btnLoadInter = FindViewById <Button>(Resource.Id.btnLoad); btnShowInter = FindViewById <Button>(Resource.Id.btnShowInter); btnOpenActiveNative = FindViewById <Button>(Resource.Id.btnOpenNative); btnLoadInter.Click += BtnLoadInter_Click; btnShowInter.Click += BtnShowInter_Click; btnOpenActiveNative.Click += BtnOpenActiveNative_Click; //Implement Banner Ads var adview = FindViewById <AdView>(Resource.Id.adView); adsMgr.CreateAds(adview); var builder = new AdLoader.Builder(ApplicationContext, GetString(Resource.String.admobNative)); var listen = new AdsUnifiedLoadListening(); listen.Ads_UnifiedNativeLoad += (obj, unifiedAds) => { var style = new NativeTemplateStyle.Builder().build(); TemplateView view = FindViewById <TemplateView>(Resource.Id.adviewTemplate); view.Visibility = ViewStates.Visible; view.SetStyles(style); view.SetNativeAd(unifiedAds); }; builder.ForUnifiedNativeAd(listen); builder.WithAdListener(listen); builder.WithNativeAdOptions(new Android.Gms.Ads.Formats.NativeAdOptions.Builder().Build()); AdLoader adloader = builder.Build(); adloader.LoadAd(new AdRequest.Builder().Build()); if (listen.Tag is null) { listen.Tag = adloader; } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.Main); //Creates webview with interface and load ad-ready HTML webView = FindViewById <WebView>(Resource.Id.webView); webView.Settings.JavaScriptEnabled = true; webView.AddJavascriptInterface(new NativeWebviewJSInterface(this), "app_interface"); webView.LoadUrl("file:///android_asset/Webview.html"); //Load NativeAd and associate to listener that comunicates with HTML AdLoader.Builder adBuilder = new AdLoader.Builder(ApplicationContext, "ca-app-pub-3940256099942544/2247696110"); //SAMPLE AD UNIT ID adBuilder.ForContentAd(new NativeAdContentListener(this, webView)); adBuilder.Build().LoadAd(new AdRequest.Builder().AddTestDevice(AdRequest.DeviceIdEmulator).Build()); }
public void CreateUnifiedAds(int numAds, AdsUnifiedLoadListening listen) { if (listen == null) { throw new ValidatingException("Not Implemented listener Unified"); } var builder = new AdLoader.Builder(context, context.GetString(Resource.String.admobNative)); builder.ForUnifiedNativeAd(listen); builder.WithAdListener(listen); builder.WithNativeAdOptions(new Android.Gms.Ads.Formats.NativeAdOptions.Builder().SetAdChoicesPlacement(5).Build()); AdLoader adloader = builder.Build(); adloader.LoadAds(new AdRequest.Builder().Build(), numAds); if (listen.Tag is null) { listen.Tag = adloader; } }
public void Initialize() { if (Loader != null) { throw new InvalidOperationException("AdAgent.Initialize() should only be called once."); } var builder = new AdLoader.Builder(UIRuntime.CurrentActivity, UnitId); builder.ForUnifiedNativeAd(new UnifiedNativeAdListener(this)); var adOptions = new NativeAdOptions.Builder() .SetVideoOptions(new VideoOptions.Builder().SetStartMuted(true).Build()) .Build(); builder.WithNativeAdOptions(adOptions); builder.WithAdListener(new ZebbleAdListener(this)); Loader = builder.Build(); }
void CreateAdLoader() { var view = Element as AdMobNativeView; if (view == null || string.IsNullOrWhiteSpace(view.UnitId) || view.AdMob == null) { return; } var nativeAdOptionsBuilder = new NativeAdOptions.Builder(); var adLoaderBuilder = new AdLoader.Builder(Context, view.UnitId); adLoaderBuilder .ForUnifiedNativeAd(this) .WithAdListener(new MyAdListener(this)) .WithNativeAdOptions(nativeAdOptionsBuilder.Build()); adLoader = adLoaderBuilder.Build(); }