In android app when we try to load unity banner, medium rectangle ads, it is showing as “Placement receives no fill” and interstitial and rewarded ads are loading and displaying perfectly even tho we replace the placement id with any random string!
Whats the issue here?
How to fix it?
implementation ‘com.unity3d.ads:unity-ads:4.12.1’
package com.v.ad.vadenhancerLibrary.AdNetworkModules;
import android.app.Activity;
import android.os.CountDownTimer;
import android.util.Log;
import com.unity3d.ads.IUnityAdsInitializationListener;
import com.unity3d.ads.IUnityAdsLoadListener;
import com.unity3d.ads.IUnityAdsShowListener;
import com.unity3d.ads.UnityAds;
import com.unity3d.services.banners.BannerErrorInfo;
import com.unity3d.services.banners.BannerView;
import com.unity3d.services.banners.UnityBannerSize;
import com.v.ad.vadenhancerLibrary.AdTypeModules.VAEBannerModule;
import com.v.ad.vadenhancerLibrary.AdTypeModules.VAEInterstitialModule;
import com.v.ad.vadenhancerLibrary.AdTypeModules.VAEMrecModule;
import com.v.ad.vadenhancerLibrary.AdTypeModules.VAERewardedModule;
import com.v.ad.vadenhancerLibrary.MainModules.VAERegister;
import com.v.ad.vadenhancerLibrary.SessionManager;
public class UnityNetworkModule {
private final SessionManager sessionManager;
private final VAERegister vaeRegister;
private static volatile UnityNetworkModule INSTANCE = null;
public BannerView BANNER_AD_UNITY;
private BannerView.IListener BANNER_LISTENER_UNITY;
public boolean BANNER_AD_UNITY_LOADED = false;
public BannerView MREC_AD_UNITY;
private BannerView.IListener MREC_LISTENER_UNITY;
public boolean MREC_AD_UNITY_LOADED = false;
public IUnityAdsLoadListener INTERSTITIAL_LISTENER_UNITY;
public IUnityAdsShowListener INTERSTITIAL_LISTENER_UNITY_2;
public boolean INTERSTITIAL_AD_UNITY_LOADED = false;
public IUnityAdsLoadListener REWARDED_LISTENER_UNITY;
public IUnityAdsShowListener REWARDED_LISTENER_UNITY_2;
public boolean REWARDED_AD_UNITY_LOADED = false;
private boolean rewarded = false;
public static UnityNetworkModule getInstance(Activity activity) {
if (INSTANCE == null) {
synchronized (UnityNetworkModule.class) {
if (INSTANCE == null) {
INSTANCE = new UnityNetworkModule(activity);
}
}
}
return INSTANCE;
}
private UnityNetworkModule(Activity activity) {
Log.e("VAEUnityNetworkModule", "UnityNetworkModule() ");
sessionManager = new SessionManager(activity);
vaeRegister = VAERegister.getInstance(activity);
}
public void initUnity(Activity activity) {
if (!sessionManager.getUnityInit()) {
Log.e("VAEUnityNetworkModule", "init unity ");
String id = "null";
String testId = "null";
boolean testMode = false;
boolean activated = false;
activated = Boolean.parseBoolean(vaeRegister.getValueOfKey(sessionManager.getAdNetworkStatusDetails(), "unity"));
testMode = Boolean.parseBoolean(vaeRegister.getValueOfKey(sessionManager.getAdNetworkDetails(), "unity_test_mode"));
testId = vaeRegister.getValueOfKey(sessionManager.getAdNetworkDetails(), "unity_test_app_id");
id = vaeRegister.getValueOfKey(sessionManager.getAdNetworkDetails(), "unity_app_id");
if (activated) {
if (testMode) {
UnityAds.initialize(activity, testId, true, new IUnityAdsInitializationListener() {
@Override
public void onInitializationComplete() {
Log.e("VAEUnityNetworkModule", "unity init success");
sessionManager.setUnityInit(true);
}
@Override
public void onInitializationFailed(UnityAds.UnityAdsInitializationError error, String message) {
Log.e("VAEUnityNetworkModule", "unity init " + message);
}
});
} else {
UnityAds.initialize(activity, id, false, new IUnityAdsInitializationListener() {
@Override
public void onInitializationComplete() {
Log.e("VAEUnityNetworkModule", "unity init success");
sessionManager.setUnityInit(true);
}
@Override
public void onInitializationFailed(UnityAds.UnityAdsInitializationError error, String message) {
Log.e("VAEUnityNetworkModule", "unity init " + message);
}
});
}
}
}
}
public void loadUnityBannerAd(Activity activity) {
Log.e("VAEUnityNetworkModule", "getUnityBanner()");
vaeRegister.logFirebase("true", "banner", "requested", "unity", "", "");
initUnity(activity);
BANNER_LISTENER_UNITY = new BannerView.IListener() {
@Override
public void onBannerLoaded(BannerView bannerAdView) {
Log.e("VAEUnityNetworkModule", "getUnityBanner onBannerLoaded()");
vaeRegister.logFirebase("true", "banner", "loaded", "unity", "", "");
BANNER_AD_UNITY = bannerAdView;
BANNER_AD_UNITY_LOADED = true;
}
@Override
public void onBannerShown(BannerView bannerAdView) {
Log.e("VAEUnityNetworkModule", "getUnityBanner onBannerShown()");
vaeRegister.logFirebase("true", "banner", "impression", "unity", String.valueOf(""), String.valueOf(""));
}
@Override
public void onBannerFailedToLoad(BannerView bannerAdView, BannerErrorInfo errorInfo) {
Log.e("VAEUnityNetworkModule", "getUnityBanner onBannerFailedToLoad() " + errorInfo.errorMessage);
vaeRegister.logFirebase("true", "banner", "failed", "unity", String.valueOf(errorInfo.errorCode), String.valueOf(errorInfo.errorMessage));
new CountDownTimer(60000, 5000) {
@Override
public void onTick(long millisUntilFinished) {
}
@Override
public void onFinish() {
VAEBannerModule.getInstance(activity).loadBannerAds(activity, "unity");
}
}.start();
}
@Override
public void onBannerClick(BannerView bannerAdView) {
Log.e("VAEUnityNetworkModule", "getUnityBanner onBannerClick()");
vaeRegister.logFirebase("true", "banner", "clicked", "unity", String.valueOf(""), String.valueOf(""));
vaeRegister.adClicked();
}
@Override
public void onBannerLeftApplication(BannerView bannerView) {
Log.e("VAEUnityNetworkModule", "getUnityBanner onBannerLeftApplication()");
}
};
BANNER_AD_UNITY = new BannerView(activity, vaeRegister.getPlacementId("unity", "banner", activity), new UnityBannerSize(320, 50));
BANNER_AD_UNITY.setListener(BANNER_LISTENER_UNITY);
BANNER_AD_UNITY.load();
}
public void loadUnityMrecAd(Activity activity) {
Log.e("VAEUnityNetworkModule", "loadUnityMrecAd()");
vaeRegister.logFirebase("true", "mrec", "requested", "unity", "", "");
initUnity(activity);
MREC_LISTENER_UNITY = new BannerView.IListener() {
@Override
public void onBannerLoaded(BannerView bannerAdView) {
Log.e("VAEUnityNetworkModule", "loadUnityMrecAd onMrecLoaded()");
vaeRegister.logFirebase("true", "mrec", "loaded", "unity", "", "");
MREC_AD_UNITY = bannerAdView;
MREC_AD_UNITY_LOADED = true;
}
@Override
public void onBannerShown(BannerView bannerAdView) {
Log.e("VAEUnityNetworkModule", "loadUnityMrecAd onMrecShown()");
vaeRegister.logFirebase("true", "mrec", "impression", "unity", String.valueOf(""), String.valueOf(""));
}
@Override
public void onBannerFailedToLoad(BannerView bannerAdView, BannerErrorInfo errorInfo) {
Log.e("VAEUnityNetworkModule", "loadUnityMrecAd onMrecFailedToLoad() " + errorInfo.errorMessage);
vaeRegister.logFirebase("true", "mrec", "failed", "unity", String.valueOf(errorInfo.errorCode), String.valueOf(errorInfo.errorMessage));
new CountDownTimer(60000, 5000) {
@Override
public void onTick(long millisUntilFinished) {
}
@Override
public void onFinish() {
VAEMrecModule.getInstance(activity).loadMrecAds(activity, "unity");
}
}.start();
}
@Override
public void onBannerClick(BannerView bannerAdView) {
Log.e("VAEUnityNetworkModule", "loadUnityMrecAd onMrecClick()");
vaeRegister.logFirebase("true", "mrec", "clicked", "unity", String.valueOf(""), String.valueOf(""));
vaeRegister.adClicked();
}
@Override
public void onBannerLeftApplication(BannerView bannerView) {
Log.e("VAEUnityNetworkModule", "loadUnityMrecAd onMrecLeftApplication()");
}
};
MREC_AD_UNITY = new BannerView(activity, vaeRegister.getPlacementId("unity", "mrec", activity), new UnityBannerSize(300, 250));
MREC_AD_UNITY.setListener(MREC_LISTENER_UNITY);
MREC_AD_UNITY.load();
}
public void loadUnityInterstitialAd(Activity activity) {
Log.e("VAEUnityNetworkModule", "loadInterstitialUnity() "+ vaeRegister.getPlacementId("unity", "interstitial", activity));
vaeRegister.logFirebase("true", "interstitial", "requested", "unity", String.valueOf(""), String.valueOf(""));
initUnity(activity);
INTERSTITIAL_LISTENER_UNITY = new IUnityAdsLoadListener() {
@Override
public void onUnityAdsAdLoaded(String placementId) {
Log.e("VAEUnityNetworkModule", "loadInterstitialUnity onUnityAdsAdLoaded()");
vaeRegister.logFirebase("true", "interstitial", "loaded", "unity", String.valueOf(""), String.valueOf(""));
INTERSTITIAL_AD_UNITY_LOADED = true;
}
@Override
public void onUnityAdsFailedToLoad(String placementId, UnityAds.UnityAdsLoadError error, String message) {
Log.e("VAEUnityNetworkModule", "loadInterstitialUnity onUnityAdsFailedToLoad() " + message);
vaeRegister.logFirebase("true", "interstitial", "failed", "unity", String.valueOf(error.toString()), String.valueOf(message));
new CountDownTimer(60000, 5000) {
@Override
public void onTick(long millisUntilFinished) {
}
@Override
public void onFinish() {
VAEInterstitialModule.getInstance(activity).loadInterstitialAds(activity, "unity");
}
}.start();
}
};
UnityAds.load(vaeRegister.getPlacementId("unity", "interstitial", activity), INTERSTITIAL_LISTENER_UNITY);
INTERSTITIAL_LISTENER_UNITY_2 = new IUnityAdsShowListener() {
@Override
public void onUnityAdsShowComplete(String placementId, UnityAds.UnityAdsShowCompletionState state) {
Log.e("VAEUnityNetworkModule", "loadInterstitialUnity onUnityAdsShowComplete()");
VAEInterstitialModule.getInstance(activity).onInterstitialAdRewarded(activity);
VAEInterstitialModule.getInstance(activity).loadInterstitialAds(activity, "unity");
}
@Override
public void onUnityAdsShowStart(String placementId) {
Log.e("VAEUnityNetworkModule", "loadInterstitialUnity onUnityAdsShowStart()");
vaeRegister.logFirebase("true", "interstitial", "impression", "unity", String.valueOf(""), String.valueOf(""));
}
@Override
public void onUnityAdsShowClick(String placementId) {
Log.e("VAEUnityNetworkModule", "loadInterstitialUnity onUnityAdsShowClick()");
vaeRegister.logFirebase("true", "interstitial", "clicked", "unity", String.valueOf(""), String.valueOf(""));
vaeRegister.adClicked();
}
@Override
public void onUnityAdsShowFailure(String placementId, UnityAds.UnityAdsShowError error, String message) {
Log.e("VAEUnityNetworkModule", "loadInterstitialUnity onUnityAdsShowFailure()" + message);
}
};
}
public void loadUnityRewardedAd(Activity activity) {
Log.e("VAEUnityNetworkModule", "loadRewardedAdUnity()");
initUnity(activity);
REWARDED_LISTENER_UNITY = new IUnityAdsLoadListener() {
@Override
public void onUnityAdsAdLoaded(String placementId) {
Log.e("VAEUnityNetworkModule", "loadRewardedAdUnity onUnityAdsAdLoaded()");
REWARDED_AD_UNITY_LOADED = true;
}
@Override
public void onUnityAdsFailedToLoad(String placementId, UnityAds.UnityAdsLoadError error, String message) {
Log.e("VAEUnityNetworkModule", "loadRewardedAdUnity onUnityAdsFailedToLoad() " + message);
vaeRegister.logFirebase("true", "rewarded", "failed", "unity", String.valueOf(""), String.valueOf(""));
new CountDownTimer(60000, 5000) {
@Override
public void onTick(long millisUntilFinished) {
}
@Override
public void onFinish() {
VAERewardedModule.getInstance(activity).loadRewardedVideoAds(activity, "unity");
}
}.start();
}
};
UnityAds.load(vaeRegister.getPlacementId("unity", "rewarded", activity), REWARDED_LISTENER_UNITY);
REWARDED_LISTENER_UNITY_2 = new IUnityAdsShowListener() {
@Override
public void onUnityAdsShowComplete(String placementId, UnityAds.UnityAdsShowCompletionState state) {
Log.e("VAEUnityNetworkModule", "loadRewardedAdUnity onUnityAdsShowComplete()");
if (state.equals(UnityAds.UnityAdsShowCompletionState.COMPLETED)) {
rewarded = true;
}
if (rewarded) {
rewarded = false;
VAERewardedModule.getInstance(activity).onRewardedVideoRewarded(activity);
VAERewardedModule.getInstance(activity).loadRewardedVideoAds(activity, "unity");
}
}
@Override
public void onUnityAdsShowStart(String placementId) {
vaeRegister.logFirebase("true", "rewarded", "impression", "unity", String.valueOf(""), String.valueOf(""));
Log.e("VAEUnityNetworkModule", "loadRewardedAdUnity onUnityAdsShowStart()");
}
@Override
public void onUnityAdsShowClick(String placementId) {
vaeRegister.logFirebase("true", "rewarded", "click", "unity", String.valueOf(""), String.valueOf(""));
Log.e("VAEUnityNetworkModule", "loadRewardedAdUnity onUnityAdsShowClick()");
vaeRegister.adClicked();
}
@Override
public void onUnityAdsShowFailure(String placementId, UnityAds.UnityAdsShowError error, String message) {
Log.e("VAEUnityNetworkModule", "loadRewardedAdUnity onUnityAdsShowFailure()");
}
};
}
}