Unity Ads 4.0 - Multiple OnUnityAdsShowComplete Callbacks for Rewarded ads - android

Using the Rewarded ad script found on the Unity Ads SDK, I'm running into an issue where the ShowAd() IUnityAdsShowListener => OnUnityAdsShowComplete is firing the debug log incrementally. The first Ad I watch returns one line stating the ad is completed, the second Ad I watch, fires off 2 logs, the third 3, then 4, etc...As if each ShowAd() subscribes a new listener to the callback. is this normal?
Im not using a button to call the ShowAd method, rather I'm just calling a function with a delegate from an AdsManager class.
public delegate void OnSuccessfulAd();
private OnSuccessfulAd _myCallback = null;
public void ShowAd(OnSuccessfulAd myMethod)
{
_myCallback = myMethod;
Advertisement.Show(_adUnitId, this);
}
public void OnUnityAdsShowComplete(string adUnitId, UnityAdsShowCompletionState showCompletionState)
{
if (adUnitId.Equals(_adUnitId) && showCompletionState.Equals(UnityAdsShowCompletionState.COMPLETED))
{
Debug.Log("Unity Ads Rewarded Ad Completed"); //Gets called more times each ad
// Grant a reward.
_myCallback?.Invoke();
}
}

Experiencing the same issue. As a temporary solution I nullify _myCallback after invoking it

I am working on the Ads 4.0.0 version in Unity.
What I observed even for Button Click is that its giving multiple Logs in Unity Editor.
However if I run the Code in my mobile Build its working as expected only 1 Log gets generated and Reward also remains same on multiple ad watches.
The issues seems to be in the CallBack in unity, My suggestion would be Try the Build in your App Once Hopefully that fixes the issue.
Unity Rewarded Ads Code from Official Page
As Unity has Deprecated most of the Previous Listeners in the New Ads 4.0.0 I think its better to cross check in the Build.

I was facing the exact same issue.
My OnUnityAdsShowComplete event callback is invoking one of my delegate.
Every references in my delegate was not accessible.
Look like the OnUnityAdsShowComplete is done on a different thread than the main one.
If in your delegate callback you have a simple Time.timeScale=1f, this should cause a crash since Time is no reachable.
Also this has observable only with reward Ads type.
My solution was to call the show() method inside a coroutine.
By having a flag set i.e. isAdRunning
You can poll that flag and when the flag is false isAdRunnin = false then you can call your delegate.
Very annoying.
Here an example. To make the code the simpliest as possible. All the IUnityAds interfaces are in the same class. This is why you will see this as listener arguments.
using UnityEngine.Advertisements;
private bool isAdsRunning = false;
// Ads start callback
public void OnUnityAdsShowStart(string placementId)
{
isAdsRunning = true;
}
// Ads complete callback
public void OnUnityAdsShowComplete(string placementId, UnityAdsShowCompletionState showCompletionState)
{
isAdsRunning = false;
}
// Entry point to show reward ads
public void ShowRewardedAd()
{
StartCoroutine(RewardRoutine());
}
IEnumerator RewardRoutine()
{
while (Advertisement.isShowing)
{
yield return null;
}
// In 4.0 Ads need to be loaded first, after initialization
// just another flag to make sure everything is initialized :)
while (!isAdLoaded)
{
yield return null;
}
// Show Ads
Advertisement.Show(adsUnitIdReward, this);
yield return new WaitForSeconds(0.25f);
while(isAdsRunning)
{
yield return null;
}
// My custom delegate
AdAction.Invoke();
}
Peace and Love.

Related

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.

How Can I Integrate mobileCore Stickeez Ad?

I explored mobileCore a month ago and decided to use today. But I couldnt integrate.
My Code for İntegrate Stickeez Ad Type:
MobileCore.init(MainActivity.this, "4U5PUKTA688XO2HBFI8O2SPYVVJ47",
MobileCore.LOG_TYPE.PRODUCTION,MobileCore.AD_UNITS.INTERSTITIAL, MobileCore.AD_UNITS.STICKEEZ);
MobileCore.showStickee(MainActivity.this, MobileCore.AD_UNIT_TRIGGER.APP_START);
I dont know why showStickee but it isnt wrong. How can I fix it?
It seems that you're trying to show the ad unit before it is ready. We recommend to use the Ad Unit Event Listener to confirm that the ad unit is ready before calling showStickee(), or at least to not call it together with MobileCore.Init().
Also, if you're using the latest version (v2.0), note that we've added a new loadAdUnit() method that requires to manually fetch the ads before displaying.
Here's an example using Android SDK v2.0:
First, In the onCreate() method of your main activity, Init the SDK:
MobileCore.init(MainActivity.this, *YOUR_DEVELOPER_HASH_HERE*,
MobileCore.LOG_TYPE.PRODUCTION,MobileCore.AD_UNITS.INTERSTITIAL, MobileCore.AD_UNITS.STICKEEZ);
Now here's an example code that loads the ad unit after Init has finished and then displays the ad upon receiving AD_UNIT_READY event:
MobileCore.setAdUnitEventListener(new AdUnitEventListener() {
#Override
public void onAdUnitEvent(MobileCore.AD_UNITS adUnit, EVENT_TYPE eventType,
MobileCore.AD_UNIT_TRIGGER... trigger) {
if (adUnit == MobileCore.AD_UNITS.STICKEEZ) {
if (eventType == EVENT_TYPE.AD_UNIT_INIT_SUCCEEDED) {
MobileCore.loadAdUnit(MobileCore.AD_UNITS.STICKEEZ, MobileCore.AD_UNIT_TRIGGER.APP_START);
}
else if (eventType == AdUnitEventListener.EVENT_TYPE.AD_UNIT_READY) {
for (MobileCore.AD_UNIT_TRIGGER myTrigger : trigger) {
if (myTrigger.equals(MobileCore.AD_UNIT_TRIGGER.APP_START)) {
MobileCore.showStickee(MainActivity.this,
MobileCore.AD_UNIT_TRIGGER.APP_START);
}
}
}
}
}
});
Feel free to contact us at support#mobilecore.com with any question.

Particular overload of Azure Mobile Service invokeApi is not working while calling custom API

Where is the documentation/sample for all overloads of invokeApi function for Azure Mobile Service client SDK for Android?
I found this article and tried following code, which does not work. There are no compile time or run time errors, invokeApi gets called, but it does not come back to onSuccess or onFailure. If I call invokeApi without order object, everything works as expected
PizzaOrder order = new PizzaOrder();
order.Size = "Large";
order.Flavor = "Four cheeses";
order.UserPhone = "555-555-1234";
ListenableFuture<PizzaOrderResponse> testresult = mClient.invokeApi("bookservice", order, PizzaOrderResponse.class);
Futures.addCallback(testresult, new FutureCallback<PizzaOrderResponse>() {
#Override
public void onFailure(Throwable exc) {
// failure handling code here
}
#Override
public void onSuccess(PizzaOrderResponse testresult) {
// success handling code here
}
});
One of the properties in the data object being returned by the custom API had incorrect data type. I am still not sure where the good documentation is and why custom API call did not fail but at least it is working now.

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?

android usage of "controller.query(activity);" in scoreloop

i am attempting to implement a built in controller that is part of the scoreloop library. the documentation states:
Basic Usage:
To invoke the TOS dialog if it was not accepted previously, the following code may be used:
final TermsOfServiceController controller = new TermsOfServiceController(new TermsOfServiceControllerObserver() {
#Override
public void termsOfServiceControllerDidFinish(final TermsOfServiceController controller, final Boolean accepted) {
if(accepted != null) {
// we have conclusive result.
if(accepted) {
// user did accept
}
else {
// user did reject
}
}
}
});
controller.query(activity);
but when i paste this into my code i get the following syntax errors:
am i using this incorrectly? how and where would this be used any ideas?
EDIT: after moving the statement to the method where i want to show the dialog i now get the following error:
You seem to be calling controller.query(activity) in a class body where a declaration is expected. Move the statement controller.query(activity) to a method where you would like to show the dialog.

Categories

Resources