Esempio n. 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;
            }
        }
Esempio n. 2
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);
        }