Admob Banner Ads Best Practice

How to Interrogate Admob banner ads best and right way

    1. Add Internet permission in Manifests
  <uses-permission android:name="android.permission.INTERNET" />  
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />  
    2. Add Admob Ads Dependencies
 // Admob Ads  
   implementation 'com.google.android.gms:play-services-ads:+'  
    3. Add Admob Meta In Manifests 
  <meta-data  
       android:name="com.google.android.gms.ads.APPLICATION_ID"  
       android:value="ca-app-pub-3940256099942544~3347511713" />  
    4. Create Public Class For Banner Ads
 public static class BannerAds {  
     public static void loadAds(LinearLayout container, Context context) {  
       MobileAds.initialize(context, new OnInitializationCompleteListener() {  
         @Override  
         public void onInitializationComplete(InitializationStatus initializationStatus) {  
         }  
       });  
       AdView adView = new AdView(context);  
       adView.setAdUnitId("ca-app-pub-3940256099942544/6300978111");  
       container.addView(adView);  
       AdRequest adRequest = new AdRequest.Builder().build();  
       adView.setAdSize(AdSize.BANNER);  
       adView.loadAd(adRequest);  
     }  
   }  
    5. XML Layout 
   <LinearLayout  
     android:id="@+id/bannerAds"  
     android:layout_width="match_parent"  
     android:layout_height="wrap_content"  
     android:orientation="vertical"  
     android:layout_alignParentBottom="true"  
     />  
    6. Set Public Variable
 LinearLayout bannerAds;  
    7. Initialize And Show Ads
 bannerAds = findViewById(R.id.bannerAds);  
 BannerAds.loadAds(bannerAds, MainActivity.this);  

 Thanks For Visit
Next Post Previous Post
No Comment
Add Comment
comment url