01 Step (অ্যাপ এর ভিতরে এস ডি কে এড করুন) build.gradle
implementation 'androidx.annotation:annotation:1.0.0'implementation 'com.facebook.android:audience-network-sdk:6.8.0'implementation 'com.google.android.gms:play-services-ads:20.5.0'
admob banner ads android studio,android studio,banner ads android studio,how to add admob banner ads in android studio 2020,admob android studio tutorial,implement admob banner ads in android studio,admob android studio,banner ads in android studio,android admob,admob banner ads,android admob tutorial,admob banner ads in android studio,android studio tutorial for beginners,how to implement admob banner ads in android studio,how to use admob in android
02: Step (Add ) strings.xml
<string name="ad_app_id" translatable="false">ca-app-pub-3940256099942544~3347511713</string><string name="banner_ad_unit_id" translatable="false">ca-app-pub-3940256099942544/6300978111</string><string name="interstitial_ad_unit_id" translatable="false">ca-app-pub-3940256099942544/1033173712</string><string name="Facebook_banner_placement">IMG_16_9_APP_INSTALL#YOUR_PLACEMENT_ID</string><string name="Facebook_Interstitial_placement" translatable="false">IMG_16_9_APP_INSTALL#YOUR_PLACEMENT_ID</string>
03: Step (Add ) AndroidManifest.xml
<meta-dataandroid:name="com.google.android.gms.ads.APPLICATION_ID"android:value="@string/ad_app_id" />
04: Step (Create a) AdMobClass.Java
package com.i_techbangla.myapplication;import android.app.Activity;import android.content.Context;import android.util.Log;import androidx.annotation.NonNull;import com.google.android.gms.ads.AdError;import com.google.android.gms.ads.AdRequest;import com.google.android.gms.ads.FullScreenContentCallback;import com.google.android.gms.ads.LoadAdError;import com.google.android.gms.ads.interstitial.InterstitialAd;import com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback;public class AdMobClass extends Activity { private static final String TAG = "ADMOB"; private InterstitialAd mInterstitialAd; private Context mContext; public AdMobClass(Context mContext) { this.mContext = mContext; } public void initInterstitialAd() { AdRequest adRequest = new AdRequest.Builder().build(); InterstitialAd.load(mContext,mContext.getString(R.string.interstitial_ad_unit_id), adRequest, new InterstitialAdLoadCallback() { private AdMobClass mContext; @Override public void onAdLoaded(@NonNull InterstitialAd interstitialAd) { mInterstitialAd = interstitialAd; Log.i(TAG, "onAdLoaded"); mInterstitialAd.setFullScreenContentCallback(new FullScreenContentCallback(){ @Override public void onAdDismissedFullScreenContent() { } @Override public void onAdFailedToShowFullScreenContent(AdError adError) { } @Override public void onAdShowedFullScreenContent() { mInterstitialAd = null; } }); mInterstitialAd.show(this.mContext); } @Override public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) { this.mContext.mInterstitialAd=null; }}); } @Override public void onPointerCaptureChanged(boolean hasCapture) { }}
05: Step (Create a) facebook.Java
package com.i_techbangla.myapplication;import android.app.Activity;import android.content.Context;import android.util.Log;import com.facebook.ads.Ad;import com.facebook.ads.AdError;import com.facebook.ads.AudienceNetworkAds;import com.facebook.ads.InterstitialAd;import com.facebook.ads.InterstitialAdListener;public class facebook extends Activity { private static final String TAG = "ADMOB"; private InterstitialAd interstitialAd; private Context mContext; public facebook(Context mContext) { this.mContext = mContext; AudienceNetworkAds.initialize(mContext); } public void facebook_ads() { interstitialAd = new InterstitialAd(mContext, mContext.getString(R.string.Facebook_Interstitial_placement)); // Create listeners for the Interstitial Ad InterstitialAdListener interstitialAdListener = new InterstitialAdListener() { @Override public void onInterstitialDisplayed(Ad ad) { // Interstitial ad displayed callback Log.e(TAG, "Interstitial ad displayed."); } @Override public void onInterstitialDismissed(Ad ad) { // Interstitial dismissed callback Log.e(TAG, "Interstitial ad dismissed."); } @Override public void onError(Ad ad, AdError adError) { // Ad error callback Log.e(TAG, "Interstitial ad failed to load: " + adError.getErrorMessage()); } @Override public void onAdLoaded(Ad ad) { // Interstitial ad is loaded and ready to be displayed Log.d(TAG, "Interstitial ad is loaded and ready to be displayed!"); // Show the ad interstitialAd.show(); } @Override public void onAdClicked(Ad ad) { // Ad clicked callback Log.d(TAG, "Interstitial ad clicked!"); } @Override public void onLoggingImpression(Ad ad) { // Ad impression logged callback Log.d(TAG, "Interstitial ad impression logged!"); } }; // For auto play video ads, it's recommended to load the ad // at least 30 seconds before it is shown interstitialAd.loadAd( interstitialAd.buildLoadAdConfig() .withAdListener(interstitialAdListener) .build()); } @Override public void onPointerCaptureChanged(boolean hasCapture) { }}
06: Step (Your activity ) activity.java
Below this class,public class
private AdMobClass admob;private facebook facebook;
07: Step (Call Facebook & AdMobClass ,Display Ads ) activity.java
/// Admob Call admob = new AdMobClass(getApplicationContext()); /// facebook Call facebook = new facebook(getApplicationContext()); /// admob Ads Call Display ads admob.initInterstitialAd();/// facebook Ads Call Display ads facebook.facebook_ads();
Post a Comment