Android Question FirebaseAdMob2 - App Open Ads

Erel

Administrator
Staff member
Licensed User
 
Upvote 0

Lucas Eduardo

Active Member
Licensed User
I'm trying to implement RewardedInterstitialAd, I managed to receive the ad but i stucked in show it. Could you help me?

in the module AdsHelper to load the ad, it's working
B4X:
Public Sub IntersticialRewardedAd (RewardedInterstitialAdAdUnit As String)
    Dim RewardedInterstitialAd As JavaObject
    RewardedInterstitialAd.InitializeStatic("com.google.android.gms.ads.rewardedinterstitial.RewardedInterstitialAd")
    AppIntersticialRAdCallback.InitializeNewInstance(Application.PackageName & ".adshelper$MyAddOpenAdCallbackI", Null)
    AppIntersticialRAdFullScreenCallback.InitializeNewInstance(Application.PackageName & ".adshelper$MyFullScreenContentCallbackI", Null)
    Do While True
        If AppIntersticialRAdCallback.GetField("ad") = Null Then
            RewardedInterstitialAd.RunMethod("load", Array(ctxt, RewardedInterstitialAdAdUnit, GetAdRequest, AppIntersticialRAdCallback))
        End If
        Sleep(60000)
    Loop
End Sub


my inline Java in module AdsHelper
B4X:
#if java
import com.google.android.gms.ads.rewardedinterstitial.*;
import com.google.android.gms.ads.rewardedinterstitial.RewardedInterstitialAd;
import com.google.android.gms.ads.FullScreenContentCallback;
import com.google.android.gms.ads.*;
public static class MyAddOpenAdCallbackI extends RewardedInterstitialAdLoadCallback {
    public RewardedInterstitialAd ad;
    @Override
    public void onAdFailedToLoad(LoadAdError adError) {
        BA.Log("Failed to load RewardedInterstitialAd: " + adError);
    }
     @Override
    public void onAdLoaded(RewardedInterstitialAd ad) {
        BA.Log("RewardedInterstitialAd received");
        this.ad = ad;
    }
  
}
public static class MyFullScreenContentCallbackI extends FullScreenContentCallback {
    public boolean isShowingAd;  
    @Override
    public void onAdDismissedFullScreenContent() {
        BA.Log("full screen content dismissed RewardedInterstitialAd");
          isShowingAd = false;
    }

    @Override
    public void onAdFailedToShowFullScreenContent(AdError adError) {}

    @Override
    public void onAdShowedFullScreenContent() {
      isShowingAd = true;
    }
}
#End If


In the tutorial from google they tell to implement the interface OnUserEarnedRewardListener in Class, i do not know how to do this

code from google tutorial
B4X:
public class MainActivity extends AppCompatActivity implements OnUserEarnedRewardListener {
  ...
  @Override
  public void onUserEarnedReward(@NonNull RewardItem rewardItem) {
    Log.i(TAG, "onUserEarnedReward");
    // TODO: Reward the user!
  }
}



my current code to show the ad, but it not working
B4X:
Public Sub ShowIntersticialRewardedAdIfAvailable As Boolean
    If AppIntersticialRAdCallback.IsInitialized = False Then Return False
    If AppIntersticialRAdFullScreenCallback.GetField("isShowingAd") = True Then Return True

    Dim ad As JavaObject = AppIntersticialRAdCallback.GetField("ad")
    If ad.IsInitialized Then
        ad.RunMethod("OnUserEarnedRewardListener", Array(AppIntersticialRAdFullScreenCallback))
        ad.RunMethod("show", Array(ctxt))
        AppIntersticialRAdCallback.SetField("ad", Null)
        Return True
    Else
        Return False
    End If
End Sub


Thank you.
 

Attachments

  • MobileAds.zip
    13.7 KB · Views: 35
Last edited:
Upvote 0
Top