How to Implement Admob Ads in Android Studio|| Banner and interstitial ads 2020
Google Test ID :
1. Sample AdMob App test ID: ca-app-pub-3940256099942544~3347511713
2. Banner test ID : ca-app-pub-3940256099942544/6300978111
How To Get Device ID for testing ads
1. open LOGCAT in Android Studio
2. in search box search addtestdevice
3. you will get your device id
Note : copy only odes and paste in your project
Recommended :
1. Android Studio
2. Ad Mob ID.
Lets Start :
1. Open build.gradle (excerpt) and check below code is there, if not than paste it
allprojects {repositories {google()jcenter()}}
2. Add below "dependencies" in build.gradle and click sync
implementation 'com.google.android.gms:play-services-ads:17.2.1'
3. Update your AndroidManifest.xml
<application><meta-dataandroid:name="com.google.android.gms.ads.APPLICATION_ID"android:value="YOUR_ADMOB_APP_ID"/></application>
note : replace your ADMOB APP ID in above black code or you can also add google test id to test your ad
4. Initialize Mobile Ads SDK
Open MainActivity.java
In package : import com.google.android.gms.ads.MobileAds;
in protected void : MobileAds.initialize(this, "YOUR_ADMOB_APP_ID");
note : replace your ADMOB APP ID in above black code or you can also add google test id to test your ad
Click SYNC
Now Insert banner ad code :
1. open main_activity.xml
under RelativeLayout section copy below code :
<com.google.android.gms.ads.AdViewxmlns:ads="http://schemas.android.com/apk/res-auto"android:id="@+id/adView"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerHorizontal="true"android:layout_alignParentBottom="true"ads:adSize="SMART_BANNER"ads:adUnitId="ca-app-pub-3940256099942544/6300978111"></com.google.android.gms.ads.AdView>
note : replace your ADMOB ADUNIT ID in above black code or you can also add google test id to test your ad
2. Load an ad
open MainActivity
in package :
import com.google.android.gms.ads.AdRequest;import com.google.android.gms.ads.AdView;
in public class : private AdView mAdView;
in protect void (below initialize code) :
mAdView = findViewById(R.id.adView);AdRequest adRequest = new AdRequest.Builder().build();mAdView.loadAd(adRequest);
click sync
That's it! Your app is now ready to display banner ads.
How To Get Device ID for testing ads
1. open LOGCAT in Android Studio
2. in search box search addtestdevice
3. you will get your device id
4. to add test device
AdRequest request = new AdRequest.Builder().addTestDevice("your device id").build();
4 Comments
bro just one question what ad network you are using on this website i can see some pop ads too thanks you have good knowledge keep growing
ReplyDeleteThanks for your comment! Bro I am using Adsterra and I have also made a separate video on that you can watch easily on my channel ;)
DeleteBro source Code mil sakta hai kya please request
ReplyDeleteweb view based application me admob lagane se admob suspend hojaega kya jabke wo google adsense se connect bhi na hoto? plz confirm it you told in 6:56
ReplyDeleteWARNING:
Don't do spam comments!