Discussion Forums  >  Suggestions, Ideas, Wish List

Replies: 5    Views: 65

buzzbt
Android Fan
Profile
Posts: 229
Reg: Nov 14, 2011
las vegas
6,490
10/04/17 02:37 PM (2 weeks ago)

How to integrate Android and iOS AdMob Banner + Interstitial ads User Guide

AdMob Banner + Interstitial ads

You’ll be able to implement both ads services into your own app in just a few simple steps.
We assume you’ve already created a Banner and/or an Interstitial UNIT ID on <a href="http://" target="_blank" rel="nofollow">http://</a>
apps.admob.com page with your existing Google AdMob account.
So let’s start with implementing your banner and interstitial ads in your Android Studio
project:

1. Import the play-services-ads into the dependencies of your build.gradle file:
dependencies {

compile 'com.google.android.gms:play-services-ads:+'
}


2. Add permission in Manifest.xml: Add the following permissions on the top of your
Manifest.xml file (right below the package name declaration and right above the
<application tag):


<!-- permissions -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />


3. Add the Banner View in your xml files: Add the following code into the xml files of
your activities where you want a Banner to be displayed in:

<com.google.android.gms.ads.AdView
android:id="@+id/admobBanner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
ads:adSize="BANNER"
ads:adUnitId="@string/ADMOB_BANNER_UNIT_ID"
/>




4. Add the Unit Id’s of your banner and interstitial ads: Add the following lines into
strings.xml file:
Of course you’ll have to replace those strings with your own Banner and Interstitial Unit
Id’s, the ones you’ve generated on <a href="http://apps.admob.com" target="_blank" rel="nofollow">http://apps.admob.com</a>

<!-- IMPORTANT: REPLACE THE STRING BELOW WITH YOUR OWN BANNER UNIT ID YOU'LL GET FROM <a href="http://apps.admob.com" target="_blank" rel="nofollow">http://apps.admob.com</a> -->
<string name="ADMOB_BANNER_UNIT_ID">ca-app-pub-9733347540588953/6212011222</string>

<!-- IMPORTANT: REPLACE THE STRING BELOW WITH YOUR OWN INTERSTITIAL UNIT ID YOU'LL GET FROM <a href="http://apps.admob.com" target="_blank" rel="nofollow">http://apps.admob.com</a> -->
<string name="ADMOB_INTERSTITIAL_UNIT_ID">ca-app-pub-9733347540588953/8497036821</
string>


5. BANNER implementation code: Enter the onCreate() method of the .java file relative
to the activity you want the banner to be displayed and add this code into it:

// ADMOB BANNER IMPLEMENTATION ------------------------------------------------------
AdView adMobBannerView = (AdView) findViewById(R.id.admobBanner);
AdRequest requestForBanner = new AdRequest.Builder().build();
adMobBannerView.loadAd(requestForBanner);
adMobBannerView.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
Log.i("log-", "BANNER is loaded!");
}
@Override
public void onAdClosed() {
Log.i("log-", "BANNER is closed!");
}
@Override
public void onAdFailedToLoad(int errorCode) {
Log .i("log-", "BANNER failed to load! error code: " + errorCode);
}
@Override
public void onAdLeftApplication() {
Log.i("log-", "BANNER left application!");
}
@Override
public void onAdOpened() {
Log.i("log-", "BANNER is opened!");
}
});


6. INTERSTITIAL implementation code: Enter the onCreate() method of the .java file
relative to the activity you want the interstitial ad to be displayed and add this code into
it:


// INTERSTITIAL AD IMPLEMENTATION ------------------------------------
final InterstitialAd interstitialAd = new InterstitialAd(this);
interstitialAd.setAdUnitId(getString(R.string.ADMOB_INTERSTITIAL_UNIT_ID));
AdRequest requestForInterstitial = new AdRequest.Builder().build();
interstitialAd.loadAd(requestForInterstitial);
interstitialAd.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
Log.i("log-", "INTERSTITIAL is loaded!");
if (interstitialAd.isLoaded()) {
interstitialAd.show();
}
}
@Override
public void onAdClosed() {
Log.i("log-", "INTERSTITIAL is closed!");
}
@Override
public void onAdFailedToLoad(int errorCode) {
Log .i("log-", "INTERSTITIAL failed to load! error code: " + errorCode);
}
@Override
public void onAdLeftApplication() {
Log.i("log-", "INTERSTITIAL left application!");
}
@Override
public void onAdOpened() {
Log.i("log-", "INTERSTITIAL is opened!");
}
});

7, paste the code inside java file

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.InterstitialAd;
import com.google.android.gms.ads.AdListener;

That’s it, you’re done, you can now run the app on your device and see the magic of
the AdMob banner and interstitial ads :)

NOTE: Check the delegate methods into the AdListener() instances of both ads
and their Log.i tags, they track all the possible operations you can do with ads,
like when you tap on it, or it fails for Google network not available at the
moment, or when the ad has been opened, etc. Enjoy!
been opened, etc.
 
SmugWimp
Smugger than thou...
Profile
Posts: 6250
Reg: Nov 07, 2012
Tamuning, GU
80,750
like
10/04/17 02:44 PM (2 weeks ago)
Hey Thanks!!

Cheers!

-- Smug
 
buzzbt
Android Fan
Profile
Posts: 229
Reg: Nov 14, 2011
las vegas
6,490
like
10/04/17 07:45 PM (2 weeks ago)
Cheers!
 
miku
Aspiring developer
Profile
Posts: 393
Reg: Feb 20, 2014
zagorje ob savi
10,480
like
10/05/17 10:20 PM (2 weeks ago)
Thanks, I will try this. Can you tell how that goes with iOS?
 
buzzbt
Android Fan
Profile
Posts: 229
Reg: Nov 14, 2011
las vegas
6,490
like
10/06/17 04:03 PM (2 weeks ago)
Hi,

AdMob Banner + Interstitial ads iOS (Xcode 9, Swift 4, iOS 11, GoogleMobileAds.framework 7.24.0 version)
https://www.dropbox.com/s/ilqnf7lrkx7jywx/AdMob%20Banner%20%2B%20Interstitial%20ads%20iOS.pdf?dl=0

GoogleMobileAds.framework

https://www.dropbox.com/s/zj36dyy5uc79mzj/GoogleMobileAds.framework.zip?dl=0
 
miku
Aspiring developer
Profile
Posts: 393
Reg: Feb 20, 2014
zagorje ob savi
10,480
like
10/10/17 08:39 AM (1 week ago)
Hello,
this is Swift version of AdMob. Isn't Buzztouch in objective-C? Did you try to implement this method yourself? What are results?
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.