Adding Admob Banner into Android Studio without using Activity Template - Step by Step

  • Published on
    21-Mar-2017

  • View
    1.300

  • Download
    1

Transcript

  • Steps in Adding

    Banner in Android Studio

    without using

    Admob Activity Template

  • 1. Add the following to your AndroidManifest.xml

    INTERNET and ACCESS_NETWORK_STATE permissions

    AdActivity, configChanges and theme.

    2. Open build.gradle and add Google Play services dependency which is required by Admob

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

    For adding Admob banner using Android Studio templates, click to see video at YouTube.

    https://www.youtube.com/watch?v=w5-L_kcj9Sk

  • 4. Add Banner ad to the XML layout

    3. Create your Banner ad ID string resource

    ca-app-pub-3940256099942544/6300978111

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

    import com.google.android.gms.ads.AdView;

    5. Import AdRequest and AdView

    For adding Admob banner using Android Studio templates, click to see video at YouTube.

    xmlns:ads="http://schemas.android.com/apk/res-auto"

    Then make sure you have added the ads parameter in your layout:

    https://www.youtube.com/watch?v=w5-L_kcj9Sk

  • 6. Put the code to load the ad into Admob banner view (named adView in this case)

    inside the onCreate method

    AdView adView = (AdView) findViewById(R.id.adView);

    AdRequest adRequest = new AdRequest.Builder()

    .setRequestAgent("android_studio:ad_template").build();

    adView.loadAd(adRequest);

    create and assign an AdView variable to the ad view (adView)

    create an AdRequest variable and instantiate it

    load the ad to ad view using the AdView variable (adView)

    by passing to its loadAd method the AdRequest variable (adRequest)

    For adding Admob banner using Android Studio templates, click to see video at YouTube.

    https://www.youtube.com/watch?v=w5-L_kcj9Sk