How to implement GoogleAdMob in Xamarin forms ?
Here are step by step instructions to implement google AdMob through Xamarin Forms.
I have used Test keys of Google AdMob for practice, visit this page to get test keys of sample ads
You can create your own Ads from Google AdMob website, and use generated keys.
I have also this project in Github to download Github project of google admob, don't forget to give star.
8) Choose 'Resource File' as type of file you want to add.
I have given 'StringReference' name of a file.
20) Right click on info.plist file and select view code.
I have also this project in Github to see code/download visit Github project of google admob, don't forget to give star.
I have also this project in Github to download Github project of google admob, don't forget to give star.
1) Create new project in Visual Studio, choose last options for new project.
choose Blank(empty) template for Xamarin project.
here, GoogleAdMob is my project name. And project is setup for both IOS and Android.
"Manage Nuget Packages".
6) In Solution explorer, right click on shared project and create a new folder
After creating Utilities folder, right click on it and choose 'Add' > 'New Item'.
8) Choose 'Resource File' as type of file you want to add.
I have given 'StringReference' name of a file.
9) double click on 'StringReference' file after creating it to open.
I have filled different types of Google Ads Sample test keys in this file,
I have filled different types of Google Ads Sample test keys in this file,
10) getting sample test key of google Ads, below is the link to get test keys of Google AdMob
11) Design main.xaml page of project
13) Now we open Android project and configure for Android mobiles.
Expand Properties
Expand Properties
And double click on 'AndroidManifest.xml' file to open.
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />
<meta-data android:name="com.google.android.gms.ads.AD_MANAGER_APP"
android:value="true"/>
15) should like this after saving.
16) now open MainActivity.cs file under Android project
"MobileAds.Initialize(ApplicationContext, "App Id");"
Also don't forget to use this package in this file to avoid error
Select "Manage Nuget Packages" to install Nuget package for IOS config.
Install all these packages under IOS project
19) Open AppDelegate.cs file of IOS project
paste this code in last,
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.Init();
MobileAds.SharedInstance.Start(CompletionHandler);
LoadApplication(new App());
return base.FinishedLaunching(app, options);
}
private void CompletionHandler(InitializationStatus status)
{
}
20) Right click on info.plist file and select view code.
add this code in last,
<key>GADApplicationIdentifier</key>
<string>ca-app-pub-3940256099942544~1458002511</string>
<key>GADIsAdManagerApp</key>
<true/>
When I will click on "show interstitial Ad" button, this Ad will show
And this video Ad will come when I will click on "show video ad"
I have also this project in Github to see code/download visit Github project of google admob, don't forget to give star.
Thanks
Ankit Yadav



















Comments
Post a Comment