ADMob not show in Android - Xamarin forms

leonardoartuso2leonardoartuso2 Member ✭✭
edited February 8 in Xamarin.Forms

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

Answers

  • YorkGoYorkGo CNMember, Xamarin Team Xamurai

    Please share your .xaml code where you place the AdMobView. And have your tried give the AdMobView a specific height?

  • leonardoartuso2leonardoartuso2 Member ✭✭
    edited February 11

    @YorkGo said:
    Please share your .xaml code where you place the AdMobView. And have your tried give the AdMobView a specific height?

    Good Morning, I Tryed yes, Width = 320 and Hight = 50, but I Tryed too add in Grid, i Tryed add BackgroundColor = Red, but i don't have Success.

    My AddView.xml

    <?xml version="1.0" encoding="utf-8" ?>
    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                 x:Class="Anuncie.Page.PageAnuncio"
                 xmlns:local="clr-namespace:Anuncie.Page;assembly=Anuncie">
        <ContentPage.Content>
            <StackLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
    
            <local:AdMobView WidthRequest="320" HeightRequest="50"/>
    
            </StackLayout>
        </ContentPage.Content>
    </ContentPage>
    
  • xam_donjoxam_donjo Member ✭✭

    I had same problem with admob. I set my adunit id in admob control and it started showing ads. You also might want to try out the default testing units to see if the ads are displaying or not. Real ads take time to show.

  • @xam_donjo said:
    I had same problem with admob. I set my adunit id in admob control and it started showing ads. You also might want to try out the default testing units to see if the ads are displaying or not. Real ads take time to show.

    Thanks, you know how many time to I see my ad? In Ad of testing a try and i have Success, my problem is in Ad real :/

  • xam_donjoxam_donjo Member ✭✭

    ad real can be a problem because it depends on advertisers in your location. Also it took me 24 hrs' to see ad in my admob unit (banner ads).

  • MarcoTronconeMarcoTroncone GBUniversity ✭✭✭

    Hi,
    if you have problems with Admob,
    you can try to use my free plugin https://www.nuget.org/packages/MarcTron.Admob.

    It supports Banner, Interstitial and Rewarded Video for Android and iOS and it's incredibly easy to use.

    On my blog you can also find a tutorial: https://www.xamarinexpert.it/blog/admob-made-easy

    If you need help, let me know.

Sign In or Register to comment.