Interstitial Ads not showing admob plugin for unity - android

I am trying to put an interstitial ad after every 5 games the user plays. What I've done is created an empty object with the following script:
using UnityEngine;
using GoogleMobileAds.Api;
public class AdBetweenGames : MonoBehaviour {
InterstitialAd interstitial;
void Start()
{
if(PlayerPrefs.GetInt("games-played", -1) % 5 == 0)
{
this.ShowInterstitial();
}
}
private void RequestInterstitial()
{
string adUnitId = "UNITID";
// Initialize an InterstitialAd.
interstitial = new InterstitialAd(adUnitId);
// Create an empty ad request.
AdRequest request = new AdRequest.Builder().Build();
// Load the interstitial with the request.
interstitial.LoadAd(request);
}
public void ShowInterstitial()
{
RequestInterstitial();
Debug.Log("Interstatial ad called.");
if (interstitial.IsLoaded())
{
interstitial.Show();
}
}
}
I am sure the code here is called properly based on the debug log. I've also tried doing banner ads and they show without a problem after 1-2 seconds. I am making an android game.
Also I was thinking, could it be that the ad needs some extra time to load and I am clicking try again too early. But then what would a solution be?

The interstitial ad of ad mob need time to load try it in update and wait for at least 4 sec and call ShowInterstitial function inside a bool set its value true in start and false it after calling the function to show ad once.

Related

google loads native ad banner only once

I'm implementing google native ads on android.Most of the code I copy/pasted from this example
The only difference is I request bunch of ads instead of one ad.Here is load function:
public void loadAds(String unitId,int count) {
if (nativeAds.size()>0) {
for(UnifiedNativeAd ad: nativeAds)
ad.destroy();
}
nativeAds =new ArrayList();
//load
AdLoader.Builder builder = new AdLoader.Builder(context, unitId);
builder.forUnifiedNativeAd(new UnifiedNativeAd.OnUnifiedNativeAdLoadedListener() {
// OnUnifiedNativeAdLoadedListener implementation.
#Override
public void onUnifiedNativeAdLoaded(UnifiedNativeAd nativeAd) {
// You must call destroy on old ads when you are done with them,
// otherwise you will have a memory leak.
//nativeAd = unifiedNativeAd;
int numAds =nativeAds.size();
int insertTo=numAds==0? firstAdPosition : firstAdPosition +numAds*(AdStep +1);
CategoryData item = new CategoryData();
item.type = ItemData.TYPE_CATEGORIES_NATIVE_AD;
if (insertTo<data.size())
data.add(insertTo, item);
item = new CategoryData();
item.type = ItemData.TYPE_CATEGORIES_SEPARATOR;
if (insertTo<data.size())
data.add(insertTo+1, item);
nativeAds.add(nativeAd);
Log.d("nativead","got ad body "+nativeAds.size()+":"+nativeAd.getBody());
notifyItemRangeInserted(insertTo,2);
}
});
VideoOptions videoOptions = new VideoOptions.Builder()
.setStartMuted(true)
.build();
NativeAdOptions adOptions = new NativeAdOptions.Builder()
.setVideoOptions(videoOptions)
.build();
builder.withNativeAdOptions(adOptions);
AdLoader adLoader = builder.withAdListener(new AdListener() {
#Override
public void onAdFailedToLoad(int errorCode) {
Log.d("nativead","error code " +errorCode);
/*
Toast.makeText(context, "Failed to load native ad: "
+ errorCode, Toast.LENGTH_SHORT).show();
*/
}
}).build();
AdRequest adRequest;
// get unpersonalized ads if needed
if(AppModel.getAppData().gdpr.eea && AppModel.getAppData().gdpr.consentStatus!= ConsentStatus.PERSONALIZED) {
Bundle extras = new Bundle();
extras.putString("npa", "1");
adRequest = new AdRequest.Builder().addNetworkExtrasBundle(AdMobAdapter.class,extras).build();
} else {
adRequest = new AdRequest.Builder().build();
}
adLoader.loadAds(adRequest,count);
//adLoader.loadAd(adRequest);
}
First time it loads ok, but if I restart the app it throws a bunch of errors:
I/Ads: Received log message: The ad request returned a no fill for the particular slot. The error log below that says 'Malformed native JSON response' is a benign warning that will be removed in a future SDK release.
Also error code 0 is passed into onAdFailedToLoad.If I clear app's data banners are loaded again but again only for single run
As you mentioned, in the comment above, you're testing it on real ad units (which is quite dangerous as you might get blocked for that).
You're getting NO_FILL, which means there is no inventory left to serve in the AdMob backend.
You can find out more about this issue (not an issue, we can call it a "thing") here.
To get proper results, always test with test ads, so that you get maximum fill rate for the ads while testing.
You'll find the ad unit ID's for test ads on this page.
And, if you still get NO_FILL error a lot in production, try using mediation to get ads from multiple ad sources. You'll never get 100% fill rate for your ads, though, so make sure you code accordingly to handle the NO_FILL.
Also, one more reminder, do not use live ads to test the app, you might get blocked by Admob/Google for doing that.

Unity RewardedVideoAds not working

Hello I am trying to implement Admob with unity, I have successfully integrated banner ads and Interstitial ads using the Test ids provided by Admob over here https://developers.google.com/admob/android/test-ads. How ever I am unable to display any rewarded Video ads. When ever I call the RewardedVidosAds nothing shows up and a debug log error displays Ad not ready. This is the following code I am using:
using System.Collections;
using System.Collections.Generic;
using System;
using UnityEngine;
using GoogleMobileAds;
using GoogleMobileAds.Api;
public class AdManager: MonoBehaviour {
public RewardBasedVideoAd rewardBasedVideoAd;
private InterstitialAd fullAdmob;
private bool rewardBasedEventHandlersSet = false;
// reward initialized
public int scoreAmount = 100;
// Use this for initialization
void Start() {
//loading both rewarded and interstitial ads in start.
LoadRewardBasedAd();
//RequestFull ();
}
// Update is called once per frame
void Update() {
}
public void LoadRewardBasedAd() {
rewardBasedVideoAd = RewardBasedVideoAd.Instance;
//Test
AdRequest adRequest = new AdRequest.Builder()
.Build();
rewardBasedVideoAd.LoadAd(adRequest, "ca-app-pub-3940256099942544/5224354917");
}
public void ShowRewardBasedAd() {
if (rewardBasedVideoAd.IsLoaded()) {
Debug.Log("Showiung video");
rewardBasedVideoAd.Show();
} else Debug.Log("not ready");
}
}
I have not currently mediated my video Ads could this be causing the problem? I read that you dont need to mediate your ads if your using a test AdId. I also get the following errors in my logcat when calling for a rewardedVideoAd
Fail to instantiate adapter com.google.DummyAdapter
Fail to load ad:3

How to measure size (KB) of an interstitial received from publicity SDK

First i apologyse for my poor english.
Our company is using a publicity SDK wich is responsible for showing interstitial at launch, during splashscreen. We don't have access directly to the view that is loaded. After initialization with app id in Application class the basic workflow is :
private MNGAdsFactory mngAdsBannerAdsFactory;
// init intertitial factory
mngAdsInterstitialAdsFactory = new MNGAdsFactory(this);
// set intertitial listener
mngAdsInterstitialAdsFactory.setInterstitialListener(this);
if (mngAdsInterstitialAdsFactory.createInterstitial()) {
//Wait callBack from interstitial listener
}else{
//adsFactory can not handle your request
}
And the success callback
#Override
public void interstitialDidLoad() {
Log.d(TAG, "interstitial did load");
}
Here is my problem. I want to measure the size (KB) of the interstitial displayed on screen in order to monitor some abuses.
Is there a way to do that?
Thank you in advance.

Android: Amazon ads never retrieved, AdListener never called

I am trying to implement Amazon Ads in my Android app, but have not been able to get any ads to display. The message in my logs is always:
D/AmazonMobileAds DefaultAdListener: Default ad listener called - Ad Failed to Load. Error code: NO_FILL, Error Message: Server Message: no results
I have set up my account, verified my tax information, I have an application key. I have tried both with testing enable and disabled with the same results. I have followed the guide for loading ads from both Amazon and Admob for backfill, but the AdMob ads are then not retrieved either. If I retrieve just AdMob ads, I have no problem with them. The relevant code is below:
in onCreate():
AdRegistration.setAppKey(getString(R.string.amazon_ad_id));
AdRegistration.enableTesting(true);
AdRegistration.enableLogging(true);
// Initialize ad views
amazonAdView = new com.amazon.device.ads.AdLayout(this);
amazonAdView.setListener(new MyAdListener());
admobAdView = new com.google.android.gms.ads.AdView(this);
admobAdView.setAdSize(com.google.android.gms.ads.AdSize.SMART_BANNER);
admobAdView.setAdUnitId(getString(R.string.banner_ad_unit_id));
Method called to retrieve an ad:
void getAd(){
// Initialize view container
adViewContainer = (ViewGroup)findViewById(R.id.adView);
amazonAdEnabled = true;
adViewContainer.removeAllViews();
adViewContainer.addView(amazonAdView);
AdTargetingOptions adOptions = new AdTargetingOptions();
adOptions.enableGeoLocation(true);
amazonAdView.loadAd(adOptions);
}
Inner AdListener class
class MyAdListener extends DefaultAdListener {
public void onAdLoaded(com.amazon.device.ads.AdLayout view, AdProperties adProperties) {
Log.d(LOG_TAG, "Ad Loaded");
if (!amazonAdEnabled) {
amazonAdEnabled = true;
adViewContainer.removeView(admobAdView);
adViewContainer.addView(amazonAdView);
}
}
public void onAdFailedToLoad(com.amazon.device.ads.AdLayout view, AdError error) {
Log.d(LOG_TAG, "Ad Failed to load");
// Call AdMob SDK for backfill
if (amazonAdEnabled) {
amazonAdEnabled = false;
adViewContainer.removeView(amazonAdView);
adViewContainer.addView(admobAdView);
}
admobAdView.loadAd((new com.google.android.gms.ads.AdRequest.Builder()).build());
}
}
In my logging, neither of the statements from the AdListener shows, so it appears that the listener is never being called. So, I have two issues here:
Why am I always receiving a NO_FILL response, even when testing?
Why is the listener never called?

AdMob interstitial doesn't show on Android

I have an Android app and I'm trying to add AdMob interstitials into it. I create them this way
interstitial = new InterstitialAd(this);
interstitial.setAdUnitId(getResources().getString(R.string.ad));
interstitial.loadAd(AdUtils.createRequest());
and when the moment is appropriate, I show them like this:
if(interstitial.isLoaded()) {
interstitial.show();
}
When I test this code on the emulator, everything is fine. But when I run it on the real device, it often (about a half of all shows) displays only a black screen with the close button and no advertisement image at all. Is there any solution to this issue?
You can try as below.
Declare this as a variable.
private InterstitialAd interstitial;
then use this part in your onCreate method
interstitial = new InterstitialAd(this, "your 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);
and at last set this outside your onCreate method so basically set below code in your activity..
#Override
public void onReceiveAd(Ad ad) {
// TODO Auto-generated method stub
if (ad == interstitial) {
interstitial.show();
}
}
Hope this will help you.

Categories

Resources