简体   繁体   中英

How to display a banner Google AdMob ads on xamarin.forms project?

had try to add google admob ads to my projects but Ads does not appear in my project. could you guide me or give me an example of how to implement it correctly? I have tried the MarcTron.Admob nuget however it does not work with android target aversion >12 or API level >31.

I am using: Android - Visual Studio for Windows - Operating System Windows 10 - Xamarin.Forms Version 5.0.0.2478 - MarcTron.Admob 1.9.0.3

my AdmobSample with

MarcTron.Admob 1.9.0.3

looks like this:

in XAML

<Frame x:Name="adsFrame" IsVisible="false" HeightRequest="50" BackgroundColor="Red">
            <controls:MTAdView 
                x:Name="myAds"
                AdsClicked="MyAds_AdsClicked"
                AdsId="ca-app-pub-3940256099942544/6300978111"
                IsVisible="false"
                VerticalOptions="EndAndExpand" 
                HeightRequest="200" 
                HorizontalOptions="CenterAndExpand"
                AdsLoaded="Ads_AdsLoaded" AdsFailedToLoad="myAds_AdsFailedToLoad">
            </controls:MTAdView>
        </Frame>

in MainPage.xaml.cs

private void Ads_AdsLoaded(object sender, EventArgs e)
        {
            MainThread.BeginInvokeOnMainThread(async () =>
            {
                await Task.Delay(3000);
                adsFrame.IsVisible = true;
                await Task.Delay(1000);
                myAds.IsVisible = true;
            });
        }

there is more help here https://github.com/marcojak/MTAdmob/issues/89

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM