AdMob update for Xamarin Forms

iooovoltsiooovolts Member ✭✭✭

Does anyone know the most up-to-date way to use AdMob for android please? Since the breaking changes in version 17.0.0 of the SDK you can no longer use the same method James Montemagno uses, and his way is pretty much what is all over the internet.
By that I mean, he initialises ads using the app id in MainActivity.cs , now it is required to be in the AndroidManifest.xaml in a <metadata/> tag.

Also, if anyone knows how to make Native ads and consume them with forms I would love to have a resource or guide I can follow for this. Thanks in advance.

Answers

  • JarvanJarvan Member, Xamarin Team Xamurai

    Before you start, you have to setup an Admob account. Next you need to create an Ad Unit. Then implement the AdView.

    Create the AdView control and pass the AdUnitId.

    public class AdMobView : View
    {
        public static readonly BindableProperty AdUnitIdProperty = BindableProperty.Create(
                       nameof(AdUnitId),
                       typeof(string),
                       typeof(AdMobView),
                       string.Empty);
    
        public string AdUnitId
        {
        get => (string)GetValue(AdUnitIdProperty);
        set => SetValue(AdUnitIdProperty, value);
        }
    }
    

    Then achieve on platform projects.

    <activity android:name="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" android:theme="@android:style/Theme.Translucent" />
    
    [assembly: ExportRenderer(typeof(AdMobView), typeof(AdMobViewRenderer))]
    namespace Admob.Droid
    {
        public class AdMobViewRenderer : ViewRenderer<AdMobView, AdView>
        {
            ...
        }
    }
    

    Check the Tutorial:
    https://xamarinhelp.com/admob-xamarin-forms-display-google-ads-mobile-app/

  • iooovoltsiooovolts Member ✭✭✭

    @Jarvan Thanks, but like I said. That way does NOT work anymore. Everything you have above is exactly the code I have. And if you look at this StackOverflow post, you will understand more what I am trying to say in this post.
    https://stackoverflow.com/questions/52786963/unable-to-get-provider-com-google-android-gms-ads-mobileadsinitprovider-java-la

  • JarvanJarvan Member, Xamarin Team Xamurai
  • batmacibatmaci DEMember ✭✭✭✭✭

    @iooovolts said:
    @Jarvan Thanks, but like I said. That way does NOT work anymore. Everything you have above is exactly the code I have. And if you look at this StackOverflow post, you will understand more what I am trying to say in this post.
    https://stackoverflow.com/questions/52786963/unable-to-get-provider-com-google-android-gms-ads-mobileadsinitprovider-java-la

    this has nothing to do with the way of using it. as the SO answer said, you just have to add your google admob id into your manifest. thats all done.

  • iooovoltsiooovolts Member ✭✭✭
    edited October 15

    @batmaci it has everything to do with it. If you had updated to the most up-to-date android sdk and used the method Jarvan has shared above you will realise you application WILL NOT even run, because you will get the error stated in the stackoverflow post i shared. Either that or there's something else wrong with my application. And if you also look in that post you will see that the chosen answer confirms google has changed the way they handle the ad-mob id.

    When I tried that new way i.e. using the metadata tag, the program runs but won't show the ad banner. Which is why I am here asking for assistance.

Sign In or Register to comment.