Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

ADMob not show in Android - Xamarin forms

$
0
0

Good Morning,

I Have a solution app in xamarin forms, and I need add ADMOB, and I do this, but, my ad not show, please help me:

My AdMob work:

I use plugin: Xamarin.GooglePlayServices.Ads - Version: 60.1142.1 - the last version.

MainActivity onCreate, My row of initialize MobileAd:
MobileAds.Initialize(ApplicationContext, "ca-app-pub-xxxxxxxxxxxxxxxxx~xxxxxxxxxx"); I tryed with ID: "xxxxxxxxxxxxxxxxxxxxxxxxxxx/xxxxxxxxxx", but I not have success

My ADMobView class:

 **public class AdMobView : View
 {
 }**

My AdMobRenderer:

    ** [assembly: ExportRenderer(typeof(AdMobView), typeof(AdMobViewRenderer))]
     namespace Anuncie.Droid.Renderes
     {
         public class AdMobViewRenderer : ViewRenderer<AdMobView, AdView>
         {
             public AdMobViewRenderer(Context context) : base(context) { }

             string adUnitId = string.Empty;
             //Note you may want to adjust this, see further down.
             AdSize adSize = AdSize.SmartBanner;
             AdView adView;
             AdView CreateNativeAdControl()
             {
                 if (adView != null)
                     return adView;

                 // This is a string in the Resources/values/strings.xml that I added or you can modify it here. This comes from admob and contains a / in it
                 adUnitId = "xxxxxxxxxxxxxxxxxxxxxxxxxxx/xxxxxxxxxx"; I tryed with ca-app-pub-xxxxxxxxxxxxxxxxx~xxxxxxxxxx, but I not have success
                 adView = new AdView(Forms.Context);
                 adView.AdSize = adSize;
                 adView.AdUnitId = adUnitId;

                 var adParams = new LinearLayout.LayoutParams(LayoutParams.WrapContent, LayoutParams.WrapContent);

                 adView.LayoutParameters = adParams;

                 adView.LoadAd(new AdRequest
                                 .Builder()
                                 .Build());
                 return adView;
             }

             protected override void OnElementChanged(ElementChangedEventArgs<AdMobView> e)
             {
                 base.OnElementChanged(e);
                 if (Control == null)
                 {
                     if (Control == null)
                     {
                         CreateNativeAdControl();
                         SetNativeControl(adView);
                     }
                 }
             }
         }
     }**

Thanks


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>