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

  • Published on
    21-Mar-2017

  • View
    1.300

  • Download
    1

Embed Size (px)

Transcript

<ul><li><p>Steps in Adding </p><p>Banner in Android Studio</p><p>without using </p><p>Admob Activity Template</p></li><li><p>1. Add the following to your AndroidManifest.xml</p><p> INTERNET and ACCESS_NETWORK_STATE permissions</p><p> AdActivity, configChanges and theme.</p><p>2. Open build.gradle and add Google Play services dependency which is required by Admob</p><p>compile 'com.google.android.gms:play-services-ads:9.2.0'</p><p>For adding Admob banner using Android Studio templates, click to see video at YouTube.</p><p>https://www.youtube.com/watch?v=w5-L_kcj9Sk</p></li><li><p>4. Add Banner ad to the XML layout </p><p>3. Create your Banner ad ID string resource</p><p>ca-app-pub-3940256099942544/6300978111</p><p>import com.google.android.gms.ads.AdRequest;</p><p>import com.google.android.gms.ads.AdView;</p><p>5. Import AdRequest and AdView</p><p>For adding Admob banner using Android Studio templates, click to see video at YouTube.</p><p>xmlns:ads="http://schemas.android.com/apk/res-auto"</p><p>Then make sure you have added the ads parameter in your layout:</p><p>https://www.youtube.com/watch?v=w5-L_kcj9Sk</p></li><li><p>6. Put the code to load the ad into Admob banner view (named adView in this case) </p><p>inside the onCreate method</p><p>AdView adView = (AdView) findViewById(R.id.adView);</p><p>AdRequest adRequest = new AdRequest.Builder()</p><p>.setRequestAgent("android_studio:ad_template").build();</p><p>adView.loadAd(adRequest);</p><p>create and assign an AdView variable to the ad view (adView)</p><p>create an AdRequest variable and instantiate it</p><p>load the ad to ad view using the AdView variable (adView) </p><p>by passing to its loadAd method the AdRequest variable (adRequest) </p><p>For adding Admob banner using Android Studio templates, click to see video at YouTube.</p><p>https://www.youtube.com/watch?v=w5-L_kcj9Sk</p></li></ul>