Implement google admob banner ads in aide ide



Tutorial on how to implement google admob banners ads into your android apps using aide ide. Banner ads occupy a spot within an app's layout, either at the top or bottom of the device screen. They stay on screen while users are interacting with the app, and can refresh automatically after a certain period of time.

First in your "build.gradle" add this lib.
compile 'com.google.android.gms:play-services-ads:+'

Next goto your "AndroidManifest.xml" and add this following codes:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />


Next goto your java files e.g "MainActivity.java" and add this following codes below.
import android.util.*;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.AdListener;
private AdView mAdView;
MobileAds.initialize(getApplicationContext(), "ca-app-pub-3940256099942544~3347511713");
mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);

mAdView.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
Log.i("Ads", "onAdLoaded");
}
@Override
public void onAdFailedToLoad(int errorCode) {
Log.i("Ads", "onAdFailedToLoad");
}
@Override
public void onAdOpened() {
Log.i("Ads", "onAdOpened");
}
@Override
public void onAdLeftApplication() {
}
@Override
public void onAdClosed() {
Log.i("Ads", "onAdClosed");
}
});



Last step goto your layout files e.g "main.xml" and add this codes:
<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>

Done, for other tutorials about google admob ads i refer to read this implement google admob interstitial ads.

Admob banner size:
Size (WxH) Description Availability AdSize constant
320x50 Banner Phones and Tablets BANNER
320x100 Large Banner Phones and Tablets LARGE_BANNER
320x250 IAB Medium Rectangle Phones and Tablets MEDIUM_RECTANGLE
468x60 IAB Full-Size Banner Tablets FULL_BANNER
720x90 IAB Leaderboard Tablets LEADERBOARD

Comments

  1. Getting error :aapt:No resource identifier found for attribute'appcomponent factory' in pacy android

    Can you please help

    ReplyDelete

Post a Comment

Leave a comment hdh

Popular posts from this blog

Implement in-app purchase in aide ide

Implement google admob interstitial ads in aide ide

Implement a-ads on blogger or website

Android play .gif file on imageview in aide ide

Aide ide tutorial - Add line graph


Malitanyo Developer blog & tutorial 2020
Refund Policy    Facebook Page    Google Play

Blogger.com