Hello guys I am using admob banner to show ads.
So I left some space at bottom so admob mob banner load.
So if user turn off internet then I want to use that banner space to show content of my activity. while if user turn on his internet again then I shrink my activity content and show admob banner again, So in short I want to grow or shrink layout space.
This is code I try. This code removes banner space if internet is off. but I dont know how to add banner again if user turn on internet.
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MobileAds.initialize(getApplicationContext(), "ca-app-pub-3940256099942544~3347511713");
final AdView mAdView = (AdView) findViewById(R.id.adView);
final AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
mAdView.setAdListener(new AdListener() {
#Override
public void onAdFailedToLoad(int i) {
//super.onAdFailedToLoad(i);
mAdView.setVisibility(View.GONE);
}
});
}
}
First you need to decide when your application will check connection again.
Check the lifecycle at https://developer.android.com/reference/android/app/Activity.html
After, lets suppose you want to check everytime the application back to the acitivty that you want to show your adview.
#Override
protected void onRestart() {
if(checkAppConnectionStatus(MainActivity.this)){mAdView.setVisibility(View.VISIBLE);}
else{ mAdView.setVisibility(View.GONE);}
super.onRestart();
}
public static boolean checkAppConnectionStatus(Context context) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (cm.getActiveNetworkInfo() != null
&& cm.getActiveNetworkInfo().isAvailable()
&& cm.getActiveNetworkInfo().isConnected()) {
return true;
}else{
return false;
}
}
Check my other answer to know more about how to use like in an utils class appConnectionStatus:
Internet Connection
Related
I am using native Admob ad for android app but everytime i am getting
Failed to load ad : 0
when i used addTestDevice(deviceId) is working fine.
My Code:
private void refreshAd(boolean requestAppInstallAds, boolean requestContentAds, final LinearLayout mLayout) {
AdLoader adLoader = new AdLoader.Builder(mContext, Config.ADMOB_AD_UNIT_ID)
.forAppInstallAd(new NativeAppInstallAd.OnAppInstallAdLoadedListener() {
#Override
public void onAppInstallAdLoaded(NativeAppInstallAd appInstallAd) {
// Show the app install ad.
NativeAppInstallAdView adView = (NativeAppInstallAdView) ((AppCompatActivity) mContext).getLayoutInflater()
.inflate(R.layout.ad_app_install, null);
populateAppInstallAdView(appInstallAd, adView);
mLayout.removeAllViews();
mLayout.addView(adView);
}
})
.forContentAd(new NativeContentAd.OnContentAdLoadedListener() {
#Override
public void onContentAdLoaded(NativeContentAd contentAd) {
// Show the content ad.
}
})
.withAdListener(new AdListener() {
#Override
public void onAdFailedToLoad(int errorCode) {
// Handle the failure by logging, altering the UI, etc.
Log.d("Opennaukri","errorCode = "+errorCode);
}
})
.withNativeAdOptions(new NativeAdOptions.Builder()
// Methods in the NativeAdOptions.Builder class can be
// used here to specify individual options settings.
.build())
.build();
adLoader.loadAd(new AdRequest.Builder().build());
// .addTestDevice("E9990FA9258AD0601F492495AC3F15EB").build());
// // Check the LogCat to get your test device ID
// .addTestDevice("B7BEE8B7CDBAC269CBB598F9DB6C4769")
// Check the LogCat to get your test device ID
}
private void populateAppInstallAdView(NativeAppInstallAd nativeAppInstallAd,
NativeAppInstallAdView adView) {
adView.setHeadlineView(adView.findViewById(R.id.appinstall_headline));
// adView.setImageView(adView.findViewById(R.id.appinstall_image));
adView.setBodyView(adView.findViewById(R.id.appinstall_body));
adView.setCallToActionView(adView.findViewById(R.id.appinstall_call_to_action));
adView.setIconView(adView.findViewById(R.id.appinstall_app_icon));
adView.setPriceView(adView.findViewById(R.id.appinstall_price));
adView.setStarRatingView(adView.findViewById(R.id.appinstall_stars));
adView.setStoreView(adView.findViewById(R.id.appinstall_store));
// Some assets are guaranteed to be in every NativeAppInstallAd.
((TextView) adView.getHeadlineView()).setText(nativeAppInstallAd.getHeadline());
((TextView) adView.getBodyView()).setText(nativeAppInstallAd.getBody());
((TextView) adView.getCallToActionView()).setText(nativeAppInstallAd.getCallToAction());
((ImageView) adView.getIconView()).setImageDrawable(nativeAppInstallAd.getIcon()
.getDrawable());
// Some aren't guaranteed, however, and should be checked.
if (nativeAppInstallAd.getPrice() == null) {
adView.getPriceView().setVisibility(View.INVISIBLE);
} else {
adView.getPriceView().setVisibility(View.VISIBLE);
((TextView) adView.getPriceView()).setText(nativeAppInstallAd.getPrice());
}
if (nativeAppInstallAd.getStore() == null) {
adView.getStoreView().setVisibility(View.INVISIBLE);
} else {
adView.getStoreView().setVisibility(View.VISIBLE);
((TextView) adView.getStoreView()).setText(nativeAppInstallAd.getStore());
}
if (nativeAppInstallAd.getStarRating() == null) {
adView.getStarRatingView().setVisibility(View.INVISIBLE);
} else {
((RatingBar) adView.getStarRatingView())
.setRating(nativeAppInstallAd.getStarRating().floatValue());
adView.getStarRatingView().setVisibility(View.VISIBLE);
}
// Assign native ad object to the native view.
adView.setNativeAd(nativeAppInstallAd);
}
Steps to see ads in your app:
1) add internet permision in your manifest file
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
2) In the Gradle file insert this line within dependencies
compile 'com.google.android.gms:play-services-ads:7.5.0'
3) now we need to display the add so we add these few lines in the layout
anyLayout xmlns:android...
xmlns:ads = "http://schemas.android.com/apk/res-auto"
...
<com.google.android.gms.ads.AdView
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-xxxxxxxxxxxxxxx/xxxxxxxxx.">
</com.google.android.gms.ads.AdView>
4) finally we need to load the ad in the layout, which only requires 3 lines:
AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
If you run the app from the emulator or you check in the layout editor (in android studio) you will see how you ad will look like. If everythings goes right in the layout editor you will see a white banner with "ads by google" (or something like that) and if you run the app in the emulator a dummy banner will show up.
Once you build the apk (signed or unsigned) and install it on a device you won't see any ad yet because google admob need some time between you register a new app to deliver ads and when the ads start to appear (<12h).
Hope this helps!
I had success with the following code:
private LinearLayout mAdContainer;
private NativeExpressAdView mAdmobAdView;
private AdRequest mAdmobAdRequest;
[...]
private void loadAds() {
// find out the width of the device in dp
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
float deviceWidthInDp = displayMetrics.widthPixels / displayMetrics.density;
int adWidth = (int)(deviceWidthInDp);
mAdContainer.removeAllViews();
mAdmobAdView = new NativeExpressAdView(this);
mAdmobAdView.setAdSize(new AdSize(adWidth, 250)); // AdSize(width, height), height ranges from 80 to 1200
mAdContainer.addView(mAdmobAdView);
mAdmobAdView.setAdUnitId(getString(R.string.admob_id)); // set your admob id
mAdmobAdRequest = new AdRequest.Builder()
.build();
mAdmobAdView.loadAd(mAdmobAdRequest);
}
Some user intentionally try to click banner ads many times.Due to this we face problem of account suspension or termination. Does anyone know how to stop the ad being loading if it cross some limit(for example 3).
AdView adView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
.setRequestAgent("android_studio:ad_template").build();
adView.loadAd(adRequest);
if(currentbannerclick>3)
{
// some code to not load the ad.
}
LinearLayout id=container
AdView id=adView
if(currentbannerclick>3)
container.removeView(adView);
Thank you everyone for your answer.
You can identify if Ad is clicked using Activity life-cycle callbacks. you can then find out how much time user clicked your Ad and call adView.loadAd(adRequest); only if the user clicked your Ad less than your threshold.
You can attach an AdListener to your AdView and increase your click counter in the onAdLoaded or onAdOpened methods. More info here: https://developers.google.com/android/reference/com/google/android/gms/ads/AdListener#public-methods
This should work:
private void loadAd() {
// This is a one element array because it needs to be declared final
// TODO: you should probably load the default value from somewhere because of activity restarts
final int[] currentBannerClick = {0};
final AdView adView = (AdView) findViewById(R.id.adView);
adView.setAdListener(new AdListener() {
#Override
public void onAdOpened() {
super.onAdOpened();
currentBannerClick[0]++;
if (currentBannerClick[0] > 3) {
adView.setVisibility(View.INVISIBLE);
adView.destroy();
}
// TODO: save currentBannerClick[0] somewhere, see previous TODO comment
}
});
if (currentBannerClick[0] <= 3) {
AdRequest adRequest = new AdRequest.Builder().addTestDevice(YOUR_DEVICE_ID).build();
adView.setVisibility(View.VISIBLE);
adView.loadAd(adRequest);
} else {
adView.setVisibility(View.INVISIBLE);
}
}
You can also limit number of Ads displayed for user in AdMob System. You can set limit of 3 ads per user per minut, hour or day.
I was trying to integrate admob banner in my application several hours, but I couldn't do that, so I created new app the only purpose of which is show admob banner but it doesn't work too. here is code
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AdView adView = new AdView(this, AdSize.BANNER, "XXX");
adView.setVisibility(View.VISIBLE);
RelativeLayout layout = new RelativeLayout(this);
RelativeLayout.LayoutParams adParams =
new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
adParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
layout.addView(adView, adParams);
setContentView(layout);
AdRequest adRequest = new AdRequest();
adView.loadAd(adRequest);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
and here is my manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.zzzzzz_admobtest"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.zzzzzz_admobtest.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
</application>
</manifest>
what am I doing wrong?
Also, when I output adView.isActivated() and adView.isReady() they both are false.
I am using "XXX" instead of ID because I don't have one. Could it be a problem?
I am using device. Here is errors on ligcat
08-07 22:43:04.248: E/ActivityThread(24181): Failed to find provider info for com.google.plus.platform
08-07 22:43:04.454: E/Ads(24181): JS: Uncaught ReferenceError: AFMA_getSdkConstants is not defined (http://media.admob.com/:1)
08-07 22:43:04.454: E/Web Console(24181): Uncaught ReferenceError: AFMA_getSdkConstants is not defined at http://media.admob.com/:1
the last 2 errors could be fixed by this code
(new Thread() {
public void run() {
Looper.prepare();
adView.loadAd(new AdRequest());
}
}).start();
as I understand the first one is not an error but just a warning.
so why this isn't work??
I am using "XXX" instead of ID because I don't have one. Could it be a
problem?
Yes. Absolutely yes. Sign up for an Admob account. Get yourself an ID and use that.
Meta-Data Tag is missing inside the Android-manifest.look into the already available resources Example
<meta-data
android:name="ADMOB_PUBLISHER_ID"
android:value="XXXX" />
This question is kinda old, but I want to answer it, because new technology appeared, which lets AdMob integration really easy. You don't need to code anything additionally in most cases, just create and .apk file and Admob will be injected into it automatically.
Enter FGL Enhance. Select, which SDK to integrate. You can select multiple various SDKs using this service, for this tutorial we'll pick only Admob from "I want to choose SDK myself".
Actually you can integrate more than 20 SDKs available by just selecting their checkbox. This list includes various ads providers, Crash reporting, Dolby Audio, etc.
Select, what development technology was used to build your app. If you want to show/hide the banner, you'll need to connect the lightweight drag-and-drop library and add 1 line of code. Depending on the technology you selected you'll be given a code sample and connector library download link.
But if you just want the banner to be present on your screen all the time, which is the easiest solution, you don't need to change your game code! This solution is called ZeroCode and it works for any development technology: event for the .apk and .ipa, which you've got from an HTML5-game or from Game Maker.
On this page you can select the ads types which will be shown in your app.
Interstitial - ads between the levels
Rewarded Video - videos, with a reward for viewing
Flexible Banner - banner, which can be hidden/shown in the game code
Persistent Banner - banner, which will stay on the screen all the time (but banner rotation is available, from AdMob settings)
Pre-Roll - ads, shown as the app starts (like in ketchapp's games)
Two last types are marked as ZeroCode. You don't need to code anything in your game to have them integrated. For our sample we'll select just a Persistent banner.
Now upload our app.
On the next screen we can select a banner type. We can use, for example SMART_BANNER or any other banner type from AdMob help. We'll also input the banner id from our AdMob account. When creating a banner in AdMob account, we can set refresh interval.
The final step - signing method selection. You ca use your own developer's certificate, then you'll be able to submit the game to the store right after the AdMob has been injected. You can select a testing certificate to test the app on your own device. Or you can download an unsigned app and sign it locally before submitting to the store.
One more progress bar...
And here we are!
The Enhance service is completely free for the developers. You'll receive the same amount of money from ads as if you'd integrated the ads manually. FGL receives the income from the SDK providers, because, in fact, FGL Enhance makes SDKs more attractive for the new developers.
source: http://www.airapport.com/2016/09/tutorial-how-to-quickly-integrate-admob.html
how to integrate AdMob and Facebook banner ads into Android applications
Build.Gradle :
implementation 'com.google.android.gms:play-services-ads:19.1.0'
implementation 'com.facebook.android:audience-network-sdk:5.+'
MyAplication.java:
AudienceNetworkAds.initialize(this);
MobileAds.initialize(this, new OnInitializationCompleteListener() {
#Override
public void onInitializationComplete(InitializationStatus initializationStatus) {
}
});
Manifest.xml:
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="App_ID_Here.."/> //Test App ID For Testing Purpose.
<activity
android:name="com.facebook.ads.AudienceNetworkActivity"
android:configChanges="keyboardHidden|orientation|screenSize" />
Permission:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
public class MainActivity extends AppCompatActivity {
private LinearLayout bannerView;
//Banner
private AdView facebookAdView;
private com.google.android.gms.ads.AdView admobAdView;
//Interstitial
private InterstitialAd facebookInterstitialAds;
private com.google.android.gms.ads.InterstitialAd adMobInterstitialAds;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bannerView = (LinearLayout) findViewById(R.id.bannerView);
//Load Banner Ads
showFacebookBannerAds();
//Load Interstitial Ads
showFacebookInterstitial();
}
private void showFacebookBannerAds() {
facebookAdView = new AdView(this, "Facebook_Banner_ID", AdSize.BANNER_HEIGHT_50);
bannerView.addView(facebookAdView);
facebookAdView.setAdListener(new AdListener() {
#Override
public void onError(Ad ad, AdError adError) {
//If Load Fail then
showAdMobBanner();
}
#Override
public void onAdLoaded(Ad ad) {
}
#Override
public void onAdClicked(Ad ad) {
}
#Override
public void onLoggingImpression(Ad ad) {
}
});
facebookAdView.loadAd();
}
private void showAdMobBanner() {
admobAdView = new com.google.android.gms.ads.AdView(this);
admobAdView.setAdSize(com.google.android.gms.ads.AdSize.SMART_BANNER);
admobAdView.setAdUnitId("ca-app-pub-3940256099942544/6300978111");
bannerView.addView(admobAdView);
admobAdView.loadAd(new AdRequest.Builder().build());
}
//Interstitial Ads
private void showFacebookInterstitial() {
facebookInterstitialAds = new InterstitialAd(this, "Interstitial_Ad_ID");
facebookInterstitialAds.setAdListener(new InterstitialAdListener() {
#Override
public void onInterstitialDisplayed(Ad ad) {
}
#Override
public void onInterstitialDismissed(Ad ad) {
//any work on ads close
finish();
}
#Override
public void onError(Ad ad, AdError adError) {
//if load fail then
loadAdMobInterstitial();
}
#Override
public void onAdLoaded(Ad ad) {
}
#Override
public void onAdClicked(Ad ad) {
}
#Override
public void onLoggingImpression(Ad ad) {
}
});
facebookInterstitialAds.loadAd();
}
private void loadAdMobInterstitial() {
adMobInterstitialAds = new com.google.android.gms.ads.InterstitialAd(this);
adMobInterstitialAds.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
adMobInterstitialAds.loadAd(new AdRequest.Builder().build());
adMobInterstitialAds.setAdListener(new AdListener() {
#Override
public void onAdClosed() {
super.onAdClosed();
//any work on ads close
finish();
}
});
}
//Interstitial Ads show on button click listener
public void showAds(View view){
if (facebookInterstitialAds.isAdLoaded())
facebookInterstitialAds.show();
else if (adMobInterstitialAds!=null)
if (adMobInterstitialAds.isLoaded())
adMobInterstitialAds.show();
}
#Override
protected void onPause() {
super.onPause();
if (admobAdView != null)
admobAdView.pause();
}
#Override
protected void onResume() {
super.onResume();
if (admobAdView != null)
admobAdView.resume();
}
#Override
protected void onDestroy() {
super.onDestroy();
if (facebookAdView != null)
facebookAdView.destroy();
if (admobAdView != null)
admobAdView.destroy();
if (facebookInterstitialAds != null)
facebookInterstitialAds.destroy();
}
}
Add Just two line in your onCreate
AdView ad = (AdView) findViewById(R.id.adView);
ad.loadAd(new AdRequest());
And add AddView in Your XML like
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="#string/ads_unit_id"
ads:loadAdsOnCreate="true" />
You can download complete source code from here
Add following lib in your dependency
compile 'com.google.android.gms:play-services-ads:7.8.0'
For Smart Banner
Add following things in xml file
<com.google.android.gms.ads.AdView
android:id="#+id/ad_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="SMART_BANNER"
ads:adUnitId="#string/banner_ad_unit_id" />
Add following things in java file
mAdView = (AdView) findViewById(R.id.ad_view);
AdRequest adRequest = new AdRequest.Builder().build();
// Start loading the ad in the background.
mAdView.loadAd(adRequest);
For Interstitial Advertise
mInterstitialAd = new InterstitialAd(MainActivity.this);
mInterstitialAd.setAdUnitId(getResources().getString(R.string.full_screen_ad_unit_id));
AdRequest adRequestFull = new AdRequest.Builder().build();
mInterstitialAd.loadAd(adRequestFull);
mInterstitialAd.setAdListener(new AdListener() {
#Override
public void onAdLoaded() {
super.onAdLoaded();
// Full screen advertise will show only after loading complete
mInterstitialAd.show();
}
});
Following this code (https://developers.google.com/mobile-ads-sdk/docs/admob/advanced):
import com.google.ads.*;
public class BannerExample extends Activity implements AdListener {
private InterstitialAd interstitial;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Create the interstitial
interstitial = new InterstitialAd(this, MY_INTERSTITIAL_UNIT_ID);
// Create ad request
AdRequest adRequest = new AdRequest();
// Begin loading your interstitial
interstitial.loadAd(adRequest);
// Set Ad Listener to use the callbacks below
interstitial.setAdListener(this);
}
#Override
public void onReceiveAd(Ad ad) {
Log.d("OK", "Received ad");
if (ad == interstitial) {
interstitial.show();
}
}
}
I have an image (my advertise) smaller than my phone screen.
I want to know if it's possible to resize the view created into the java code. (in onCreate() or onReceiveAd()) for adapting the size of the advertise.
LayoutParam, in CenterCrop for exemple, or simple resizing of the view !
If you want to serve an interstitial from DFP to a phone, you can set up an image in DFP, and override the size to be 320x480. Then that creative can serve, and be smaller if you want.
Or, you may be looking for a banner instead of an interstitial overlay that takes over the entire screen. In that case, you can specify a custom size for your AdView, that should match the size you set up in DFP.
I have read everything about how to implement the Custom Events in the Admob Mediation.
I have added the full packaged class name and everything is set in the Admob portal.
This is the class implementation done
public class CustomEvent implements CustomEventBanner, AdListener{
private CustomEventBannerListener bannerListener;
private AdView adView;
#Override
public void requestBannerAd(final CustomEventBannerListener listener,
final Activity activity,
String label,
String serverParameter,
AdSize adSize,
MediationAdRequest mediationAdRequest) {
// Keep the custom event listener for use later.
this.bannerListener = listener;
// Determine the best ad format to use given the adSize. If the adSize
// isn't appropriate for any format, an ad will not fill.
AdSize bestAdSize = adSize = adSize.findBestSize(
AdSize.BANNER,
AdSize.IAB_BANNER,
AdSize.IAB_LEADERBOARD,
AdSize.IAB_MRECT,
AdSize.IAB_WIDE_SKYSCRAPER);
if (bestAdSize == null) {
listener.onFailedToReceiveAd();
return;
}
// Initialize an AdView with the bestAdSize and the publisher ID.
// The publisher ID is the server parameter that you gave when creating
// the custom event.
this.adView = new AdView(activity, bestAdSize, serverParameter);
// Set the listener to register for events.
this.adView.setAdListener(this);
// Generate an ad request using custom targeting values provided in the
// MediationAdRequest.
AdRequest adRequest = new AdRequest()
.setBirthday(mediationAdRequest.getBirthday())
.setGender(mediationAdRequest.getGender())
.setKeywords(mediationAdRequest.getKeywords())
.setLocation(mediationAdRequest.getLocation());
if (mediationAdRequest.isTesting()) {
adRequest.addTestDevice(AdRequest.TEST_EMULATOR);
}
// Load the ad with the ad request.
this.adView.loadAd(adRequest);
}
#Override
public void onReceiveAd(Ad ad) {
this.bannerListener.onReceivedAd(this.adView);
}
#Override
public void onFailedToReceiveAd(Ad ad, ErrorCode errorCode) {
this.bannerListener.onFailedToReceiveAd();
}
#Override
public void onPresentScreen(Ad ad) {
this.bannerListener.onClick();
this.bannerListener.onPresentScreen();
}
#Override
public void onDismissScreen(Ad ad) {
this.bannerListener.onDismissScreen();
}
#Override
public void onLeaveApplication(Ad ad) {
this.bannerListener.onLeaveApplication();
}
}
The problem is that I really dont know how to add use my layout.add(adview) in the onReceivedAd(),
Any inputs would be helpful.
Custom Events are a little different compared to normal AdMob implementation. In requestBannerAd you create your ad network's adview, and request an ad. Once an ad is received (in this the onReceiveAd callback), you invoke:
this.bannerListener.onReceivedAd(this.adView);
You're already doing this in your code. When invoking this, you're telling the AdMob Mediation layer "Hey, I successfully loaded an ad, and here is my view for you to show." The Mediation layer takes in your adview and essentially calls layout.addView(adView) on your behalf (it adds it as a child of the main AdView you defined in your app).
So in your case, this code should just work.