locked
Native Admob Ads in Xamarin.Forms RRS feed

  • Question

  • User327222 posted

    I need to implement Native Ads in Xamarin.Forms. But I did not find any examples on Xamarin.Forms. Maybe someone has an example of using Native Ads on Xamarin.Forms and can share.

    My example of what I was trying to do: Android:

    [assembly: Dependency(typeof(NativeAd))]
    namespace Ads.Droid.Platform.Renderers.Ad
    {
        public class NativeAd : AdListener, INativeAd
        {
            Context context = Android.App.Application.Context;
    
           public void Show()
            {   
                var videoOptions = new VideoOptions.Builder().SetStartMuted(false).Build();
                var adOptions = new NativeAdOptions.Builder().SetVideoOptions(videoOptions).Build();
                AdLoader adLoader = new AdLoader.Builder(context, "ca-app-pub-3940256099942544/2247696110").WithNativeAdOptions(adOptions).Build();
    
                var request = new AdRequest.Builder();
                foreach (var item in TestDevice.GetTestDevices())
                    request.AddTestDevice(item);
    
                adLoader.LoadAd(request.Build());   
            }
        }
    }
    

    or

    [assembly: Dependency(typeof(NativeAd))]
    namespace Ads.Droid.Platform.Renderers.Ad
    {
        public class NativeAd : AdListener, INativeAd
        {
            NativeExpressAdView mAdView;
    
           public void Show()
            {   
                mAdView = new NativeExpressAdView(Android.App.Application.Context)
                {
                    AdUnitId = "ca-app-pub-3940256099942544/2247696110",
                    AdSize = AdSize.MediumRectangle
                };
                var request = new AdRequest.Builder();
                foreach (var item in TestDevice.GetTestDevices())
                    request.AddTestDevice(item);
                mAdView.LoadAd(request.Build());    
            }
        }
    }
    

    In iOS didn’t do it, but I also need an example. Maybe something needs to be changed or completed. Help me please.

    Wednesday, October 3, 2018 7:54 AM

All replies

  • User371688 posted

    @ViktorBylbas You can check : https://stackoverflow.com/questions/52624172/native-admob-ads-in-xamarin-forms-are-there-any-ready-made-solutions-examples

    Thursday, October 4, 2018 8:48 AM