Exemple #1
0
        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;
            }
        }
Exemple #2
0
        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;
            }
        }
Exemple #3
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_native);
            adsMgr = new AdsManager(ApplicationContext);

            var recyclerView = FindViewById <RecyclerView>(Resource.Id.recyclerView);
            LinearLayoutManager layoutManager = new LinearLayoutManager(this);

            layoutManager.Orientation = RecyclerView.Vertical;
            recyclerView.HasFixedSize = true;
            recyclerView.SetLayoutManager(layoutManager);
            var adapter = new NativeRecyclerAdapter();

            recyclerView.SetAdapter(adapter);

            dataAll.AddRange(GetDummyData());
            var listen = new AdsUnifiedLoadListening();

            listen.Ads_UnifiedNativeLoad += (obj, unifiedAds) =>
            {
                dataAll.Add(unifiedAds);
                var tag = ((AdsUnifiedLoadListening)obj).Tag as AdLoader;
                if (!tag.IsLoading)
                {
                    adapter.SetData(dataAll);
                }
            };

            listen.Ads_LoadFailed += (obj, errCode) =>
            {
                //Handle Ads Load Failed
            };
            listen.Ads_LeftApp += (s, e) =>
            {
                //Handle Ads clicked left app
            };
            //Max pre request 5
            adsMgr.CreateUnifiedAds(5, listen);
        }