MoPub android sdk onInterstitialLoaded never called - android

I tried to implement MoPub interstitials in my libgdx android application.
When I pass a wrong ID in the MoPubInterstitial() constructor, the onInterstitialFailed() method in the listener is called correctly, but when I pass my correct ID nothing happens.
onInterstitialLoaded() should be called eventually, but it isn't.
MoPubInterstitial.isReady() never is true.
Am I missing something?
I don't know, which part of my code I should paste. I'm out of ideas, how to debug this.
Any suggestions?

private static final String MoPubInterstitialID = "xxxxxxxxxxxxx";
private MoPubInterstitial moPubInterstitial;
moPubInterstitial = new MoPubInterstitial(this, MoPubInterstitialID);
moPubInterstitial.setInterstitialAdListener(this);
moPubInterstitial.load();
moPubInterstitialButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Log.d("MoPub", "Interstitial button clicked");
if ( moPubInterstitial.isReady() )
{
Log.d("MoPub", "Interstitial is Ready");
moPubInterstitial.show();
Log.d("MoPub", "Interstial Shown");
moPubInterstitial.forceRefresh();
}
}
});
These are all the steps that i took to make it work. Let me know if you have any questions.

Related

Unity Ads 4.0 - Multiple OnUnityAdsShowComplete Callbacks for Rewarded ads

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.

Xamarin, Android: Using the AdListener right

I'm trying to use the AdListener in C#.
I have an interstitial ad loading when the app is first started, but sometimes my ad gets skipped because it isn't fully loaded yet. I think an Adlistener should do the trick.
Unfortunately, I have NO CLUE on how to implement it. Also, there is no tutorial on how to do it in C# only in Java and I couldn't find a translation for it :(
Add:
adListener.OnAdLoaded() += (o, e) =>
{
mInterstitialAd.Show();
};
This doesn't work :(
Any help would be awesome!
You can create a class which inherits from Android.Gms.Ads.AdListener, then use the instance of this class as the Listener for your mInterstitialAd, for example:
mInterstitialAd.AdListener = new AdListener(this);
AdListener:
private class AdListener : Android.Gms.Ads.AdListener
{
private MainActivity that;
public AdListener(MainActivity t)
{
that = t;
}
public override void OnAdLoaded()
{
base.OnAdLoaded();
}
public override void OnAdClosed()
{
that.RequestNewInterstitial();
that.BeginSecondActivity();
}
}
You can also checked the official demo for xamarin android ad: AdMobExample Sample.

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.

Unlocking achievement in OpenFeint

I'm very new to OpenFeint, actually started integrating it into my game today. I can't understand one simple thing that every OpenFeint using developer should probably know. Here's the example of unlocking an achievement from OpenFeint official tutorial:
new Achievement("achievementID").unlock(new Achievement.UnlockCB () {
#Override public void onSuccess() {
MyClass.this.setResult(Activity.RESULT_OK);
MyClass.this.finish();
}
#Override public void onFailure(String exceptionMessage) {
Toast.makeText( MyClass.this,
"Error (" + exceptionMessage + ") unlocking achievement.",
Toast.LENGTH_SHORT).show();
MyClass.this.setResult(Activity.RESULT_CANCELED);
MyClass.this.finish();
}
});
Problem is that I don't want to finish my activity in onSuccess or onFailure, I just don't need to do anything here. If I just leave these two methods codeless, my game freezes an becomes totally unresponsive. What should I do? Thanks in advance.
P.S. How do you create Test Users? I've tryed every email-password combination possible and could not get it to go..
Its generally a good idea to put all your communication with the internet in a AsyncTask. Not everyone has fast internet, so this will make sure the main thread doesn't lock up because of that.
That being said, I think that the setResult function is used in a startActivityForResult construction. The intent that is created in this way is only sent back to the original class if the activity is finished. So to fix this you would need to put the code in a separate activity.
I simply wrote this method in my Utility class
public static void unlockAchievement(final String achievementId, final Activity context){
final Achievement achievement = new Achievement(achievementId);
achievement.unlock(new Achievement.UnlockCB() {
#Override
public void onSuccess(boolean newUnlock) {
context.setResult(Activity.RESULT_OK);
}
#Override
public void onFailure(String exceptionMessage) {
context.setResult(Activity.RESULT_CANCELED);
Toast.makeText(context, "Error (" + exceptionMessage + ") unlocking achievement.", Toast.LENGTH_SHORT).show();
FlurryAgent.onError("unlockingAchievement", exceptionMessage, this.getClass().getSimpleName());
}
});
}

How to know when someone has clicked on an Adview?

I'm using an adview in my application and want to know when someone has clicked that Adview!
How I can do that?
The onclicklistener does not seem to work.
You can set the listener this way:
adView.setAdListener(this);
And then implement this:
#Override
public void onPresentScreen(Ad arg0) {
//OnClick here
}
The click is handled inside of the AdMob API, and I don't think there is a way to do what you are asking with the API as its against the TOS to use a "unlock feature by clicking X number of ads" model. For that reason I don't believe it is available in the API where the onclicklistener is.
Try this
mAdView.setAdListener(new AdListener() {
#Override
public void onAdOpened() {
super.onAdOpened();
}
});

Categories

Resources