- Get link
- X
- Other Apps
- Get link
- X
- Other Apps
Looking to monetize your Android app? Admob banner ads are a great way to earn some extra cash. And the good news is that implementing them is a breeze! All you need is an Admob account and a few simple steps to get started.
First things first, make sure you've got an Admob account set up and approved. This usually takes a couple of days, but once you're good to go, it's time to create your app and set up a banner ad unit.
Once you've got your ad unit set up, it's time to start integrating it into your app. Don't worry, it's not as complicated as it sounds! Android Studio makes it easy with a simple code snippet that you can add to your app's layout file.
And voila! You're now ready to start earning some extra revenue from your app. So what are you waiting for? Follow these simple steps and start cashing in on your hard work today!
First, add the below dependency required in the App-level Gradle:
dependencies {
-------
-------
implementation 'com.google.android.gms:play-services-ads:21.5.0'
}
Now implement the MainActivity.Java. The code Snippet for MainActivity.Java is given Below:
package com.epicgamers.admob;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.initialization.InitializationStatus;
import com.google.android.gms.ads.initialization.OnInitializationCompleteListener;
public class MainActivity extends AppCompatActivity {
private AdView mAdView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MobileAds.initialize(this, new OnInitializationCompleteListener() {
@Override
public void onInitializationComplete(InitializationStatus initializationStatus) {
} });
mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
}}
Copy the XML code from "https://developers.google.com/admob/android/banner" which looks something like this:
The full code Snippet for Activity_main.xml is given Below:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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">
<com.google.android.gms.ads.AdView
xmlns: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="BANNER"
ads:adUnitId="ca-app-pub-3940256099942544/6300978111">
</com.google.android.gms.ads.AdView>
</RelativeLayout>
Don't forget to change the manifest file and add the meta-data to it. The code Snippet for AndroidManifest.xml is given Below:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.Admob"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-785389512*******~**********"/>
</application>
</manifest>
Thats it folks!
- Get link
- X
- Other Apps
Comments
Can you do a video on how we can intergreate interetial ad on admob
ReplyDelete