Skip to content

Commit

Permalink
Add isAdAvailable and pollAd methods to the Interstitial, UnityRe…
Browse files Browse the repository at this point in the history
…wardedAd and UnityAppOpenAd classes in android library.

PiperOrigin-RevId: 683818191
  • Loading branch information
Mobile Ads Developer Relations authored and copybara-github committed Oct 9, 2024
1 parent 8437f8c commit 906b8ea
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,11 @@ public class Interstitial {
*/
private InterstitialAd interstitialAd;

/**
* The {@code Activity} on which the interstitial will display.
*/
private Activity activity;
/** The {@code Activity} on which the interstitial will display. */
private final Activity activity;

/**
* A listener implemented in Unity via {@code AndroidJavaProxy} to receive ad events.
*/
private UnityInterstitialAdCallback callback;
/** A listener implemented in Unity via {@code AndroidJavaProxy} to receive ad events. */
private final UnityInterstitialAdCallback callback;

public Interstitial(Activity activity, UnityInterstitialAdCallback callback) {
this.activity = activity;
Expand Down Expand Up @@ -197,6 +193,19 @@ public void run() {
});
}

/** Returns {@code true} if there is an interstitial ad available in the pre-load queue. */
public boolean isAdAvailable(@NonNull String adUnitId) {
return InterstitialAd.isAdAvailable(activity, adUnitId);
}

/**
* Retrieves the next interstitial ad available in pre-load queue, or {@code null} if no ad is
* available.
*/
public void pollAd(@NonNull String adUnitId) {
interstitialAd = InterstitialAd.pollAd(activity, adUnitId);
}

/** Returns the {@link InterstitialAd} ad unit ID. */
@Nullable
public String getAdUnitId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,19 @@ public void onAdFailedToLoad(@NonNull final LoadAdError error) {
}));
}

/**
* Retrieves the next app open ad available in Preload queue, or {@code null} if no ad is
* available.
*/
public void pollAd(@NonNull String adUnitId) {
appOpenAd = AppOpenAd.pollAd(activity, adUnitId);
}

/** Returns {@code true} if there is an interstitial ad available in the pre-load queue. */
public boolean isAdAvailable(@NonNull String adUnitId) {
return AppOpenAd.isAdAvailable(activity, adUnitId);
}

public void show() {
if (appOpenAd == null) {
Log.e(PluginUtils.LOGTAG, "Tried to show app open ad before it was ready. This should "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,14 @@ public class UnityRewardedAd {
*/
private RewardedAd rewardedAd;

/**
* The {@code Activity} on which the rewarded ad will display.
*/
private Activity activity;
/** The {@code Activity} on which the rewarded ad will display. */
private final Activity activity;

/**
* A callback implemented in Unity via {@code AndroidJavaProxy} to receive ad events.
*/
private UnityRewardedAdCallback callback;


public UnityRewardedAd(Activity activity, UnityRewardedAdCallback callback) {
this.activity = activity;
this.callback = callback;
Expand Down Expand Up @@ -178,6 +175,18 @@ public void run() {
});
}

/**
* Retrieves the next rewarded ad available in Preload queue, or {@code null} if no ad is
* available.
*/
public void pollAd(@NonNull String adUnitId) {
rewardedAd = RewardedAd.pollAd(activity, adUnitId);
}

/** Returns {@code true} if there is an interstitial ad available in the pre-load queue. */
public boolean isAdAvailable(@NonNull String adUnitId) {
return RewardedAd.isAdAvailable(activity, adUnitId);
}

/**
* Shows the rewarded ad if it has loaded.
Expand Down

0 comments on commit 906b8ea

Please sign in to comment.