Breaking News

How to create a Banner ad in Android App | Place Banner Ads




If you are an Android Developer and want to earn money from your android app. Then you have to place Ads in your Android App.

There is some type of ads you can place in your Android App.



Today, In this post we learn how to create a Banner ad in your Android App.

To place a Banner Ad, we have to create a new Admob Account and add your app there and then create a new Banner Ad there and create Ad unit Id. seen in the pictures below.


Your Application Name


Type of Ad


Banner Ad set-up


Then, in Android Studio, first, we have to add new google ads dependency in our app-level Gradle file.

app-level Gradle file
 implementation 'com.google.android.gms:play-services-ads:18.3.0'  

Then, we create a banner ad layout in our XML file.

MainActivity.xml

 <?xml version="1.0" encoding="utf-8"?>  
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
   xmlns:app="http://schemas.android.com/apk/res-auto"  
   xmlns:tools="http://schemas.android.com/tools"  
   android:layout_width="match_parent"  
   android:layout_height="match_parent"  
   tools:context=".MainActivity">  
   <TextView  
     android:layout_width="wrap_content"  
     android:layout_height="wrap_content"  
     android:text="Hello World!"  
     app:layout_constraintBottom_toBottomOf="parent"  
     app:layout_constraintLeft_toLeftOf="parent"  
     app:layout_constraintRight_toRightOf="parent"  
     app:layout_constraintTop_toTopOf="parent" />  
   <com.google.android.gms.ads.AdView  
     android:id="@+id/adView"  
     android:layout_width="wrap_content"  
     android:layout_height="wrap_content"  
     android:layout_alignParentBottom="true"  
     android:layout_centerHorizontal="true"  
     android:layout_gravity="bottom|center"  
     app:adSize="BANNER"  
     app:adUnitId="@string/bannerAdMobId">  
     </com.google.android.gms.ads.AdView>  
 </LinearLayout>  

Then place your application id in your manifest.xml under meta-data tag

For Application Id open your Admob Account and open your Ad unit then click on implementation instructions, Upper one which contains tilde (~) sign is your Application id and another one is your Ad unit Id.



Application Id and Ad Unit Id


AndroidManifest.xml

 <meta-data  
       android:name="com.google.android.gms.ads.APPLICATION_ID"  
       android:value="@string/bannerAdAppId" />  

Then create an instance and find the id in MainActivity.java and Load your Banner Ad

MainActivity.java
 public class MainActivity extends AppCompatActivity {  
   AdView madview;  
   @Override  
   protected void onCreate(Bundle savedInstanceState) {  
     super.onCreate(savedInstanceState);  
     setContentView(R.layout.activity_main);  
     madview = findViewById(R.id.adView);  
     AdRequest adRequest = new AdRequest.Builder().addTestDevice("XXXXXXXXXXXXXXXXXXXXXX").build();  
     madview.loadAd(adRequest);  
   }  
 }  

 Here, we load our ad and also add a test device because we run this ad through debugging. For test device id you can see logs of Ad-request inside run tab in Android Studio.


Find Test Device Id to run Banner Ad
  


Follow us for more posts like this, 
Subscribe Harpreet studio on Youtube  
Like Harpreet Studio on Facebook  
Follow me on Instagram 

22 comments:

  1. Great articles and great layout. Your blog post deserves all of the positive feedback it’s been getting. Phone Spy Apps

    ReplyDelete
  2. As always as widespread contractors go look at this web-site, app company
    agencies you're in inappropriate hands with those men!

    ReplyDelete
  3. The evolution of modern business is reflected in the growth of digital agencies. The concept of a digital agency, being relatively young, is clouded, vague and varying. Digital marketing

    ReplyDelete
  4. Some really marvelous work on behalf of the owner of this web site , dead great subject matter. iOS developer

    ReplyDelete
  5. Some really marvelous work on behalf of the owner of this web site , dead great subject matter. unlimited reseller hosting

    ReplyDelete
  6. Some really marvelous work on behalf of the owner of this web site , dead great subject matter. kiss918 apk

    ReplyDelete
  7. Some really marvelous work on behalf of the owner of this web site , dead great subject matter. kiss918

    ReplyDelete
  8. I like this site so much, saved to favorites . pussy888

    ReplyDelete
  9. Some really marvelous work on behalf of the owner of this web site , dead great subject matter. book accommodation in Gauteng

    ReplyDelete
  10. I absolutely love your blog and find a lot of your post’s to be exactly I’m looking for. can you offer guest writers to write content to suit your needs? I wouldn’t mind writing a post or elaborating on a few of the subjects you write in relation to here. Again, awesome weblog! XE88

    ReplyDelete
  11. Get started with wales ahead nearly every planking. Ones wales truly are a compilation of huge planks one particular depth advisors certainly is the identical to the entire hull planking however with even larger density to successfully thrust outward beyond the planking. planking ICCRC Agents in Dubai

    ReplyDelete
  12. I adore your wp web template, wherever would you obtain it through? buy copiers

    ReplyDelete
  13. Hi! Great post! Please do tell us when I will see a follow up! mega888 apk

    ReplyDelete
  14. Some really marvelous work on behalf of the owner of this web site , dead great subject matter. Islamic Apps

    ReplyDelete
  15. Quickly and easily build your web traffic and PR, which provides Web site visitors to add your page to any social bookmarking website. best reseller hosting

    ReplyDelete
  16. You have done a great job on this article. It’s very readable and highly intelligent. You have even managed to make it understandable and easy to read. You have some real writing talent. Thank you. BizOp

    ReplyDelete
  17. Great post, you have pointed out some fantastic points , I likewise think this s a very wonderful website. 안전놀이터

    ReplyDelete
  18. Thanks so much for this information. I have to let you know I concur on several of the points you make here and others may require some further review, but I can see your viewpoint. 온라인릴게임

    ReplyDelete
  19. Quickly and easily build your web traffic and PR, which provides Web site visitors to add your page to any social bookmarking website. Lodges in ladysmith

    ReplyDelete
  20. Yes i am totally agreed with this article and i just want say that this article is very nice and very informative article.I will make sure to be reading your blog more. You made a good point but I can't help but wonder, what about the other side? !!!!!!Thanks nursing test bank

    ReplyDelete
  21. I certainly appreciate your stuff provided in the blogs.
    logo companies designers

    ReplyDelete