Banner ads are a great way to monetize your Android app. In this tutorial, we will show you how to place AdMob banner ads in your Android app.
First, create a new project in Android Studio.
Next, add the following permissions to your AndroidManifest.xml file:
Then, add the following lines to your AndroidManifest.xml file:
Next, add the following code to your MainActivity.java file:
package com.example.android.admob; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; import com.google.android.gms.ads.AdMob; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TextView tv = (TextView) findViewById(R.id.textView); AdMob adMob = new AdMob(this); adMob.setAdUnitId(“ca-app-pub-3940256099942544/6300978111”); adMob.loadAd(); tv.setText(“AdMob banner loaded.”); } }
Finally, add the following lines to your activity_main.xml file: