Xamarin.Forms: Google AdMob Ads in Android – James Montemagno

2 min


0

I’ve been just lately experimenting with integrating advertisements into my purposes as an experiment. Not actually to earn a living, however to only get it setup and dealing. I just lately experimented with each Facebook Ads and Google AdMob for my iOS app “Social Post” and the outcomes have been fairly good. I mentioned this technique a number of weeks again on the Merge Conflict podcast with Frank on Monitization.

Now, it’s time to go a step additional and add some advertisements into my Xamarin.Forms utility Meetup Manager that has a number of utilization. I knew I needed to replace the app due to adjustments in Android N with SQLite, so I determine what higher time. I used to be stunned how straightforward it was to really get issues setup and working.

Registring with AdMob

So, the very first thing that you will want to do is definitely register for AdMob. This gives you two necessary items of knowledge, your “Application Code” and your “Ad Unit Id”. We will use these later, however merely go to: https://apps.admob.com, register for a brand new app, hyperlink to an app in Firebase, and you may be off working.

Downloading NuGet Package

This one is a bit tough since Xamarin.Forms requires very particular package deal variations. Search for “Google Play Ads” and the Xamarin package deal ought to be the primary one to return up. If you might be utilizing Xamarin.Forms.Maps then you need to choose 29.0.0.1, else you’ll be able to choose 29.0.0.2. (Note, that in case you are focusing on API 24+ you’ll be able to set up newer help libraries after which set up 42.1021.1+ of the advertisements sdk :))

Custom Control

For my utility I’m not including any customized information bindings or something like that for the Ad Ids, so I simply create a really very quite simple customized management in my shared code:

Ad View Renderer

Now, now we have to enter our Android undertaking and implement the customized management. Essentially only a methodology to create the native AdView after which set it when the web page masses up.

Update MainActivity

Go into your Main Activity and initialize your CellularAds from the SDK:

Update Manifest

You will now want so as to add 2 permissions:

Inside of the Application attribute you must add this particular Activity for advertisements.

Update XAML

Now we will add the customized management to the underside of your XAML.

First add your customized xmlns identify house:

Then add in the customized management and growth completed!

Success!

You ought to now have the ability to run your app and growth! Test Ad!

This in fact was only a sensible banner, however you could possibly lengthen it even additional and check out the opposite advertisements with customized renderers. Enjoy! Looking so as to add AdMob advertisements to iOS apps? I’ve you lined in my next blog found here.

Important


What's Your Reaction?

hate hate
0
hate
confused confused
0
confused
fail fail
0
fail
fun fun
0
fun
geeky geeky
0
geeky
love love
0
love
lol lol
0
lol
omg omg
0
omg
win win
0
win

0 Comments

Your email address will not be published. Required fields are marked *

Choose A Format
Trivia quiz
Series of questions with right and wrong answers that intends to check knowledge
Poll
Voting to make decisions or determine opinions
Story
Formatted Text with Embeds and Visuals
List
The Classic Internet Listicles
Meme
Upload your own images to make custom memes
Video
Youtube, Vimeo or Vine Embeds
Audio
Soundcloud or Mixcloud Embeds
Image
Photo or GIF
Gif
GIF format