Rewarded Ads
First of all, you need to create a AdstronomicAdsRewarded object and init it (with your application context in parameter). After this, you have two possibilities:
  • Display as quickly as possible the ad after loading it. For this, you can simply call the method Adstronomic.loadAndShow with the app context and the ad object as parameters.
  • Just load the ad in the background by calling the method loadAd. And, when you want to show the ad (after a specific event - For example: click on a button) you can do it with the method show.
So, for example:
Java
1
AdstronomicAdsRewarded rewardedAd = new AdstronomicAdsRewarded(getApplicationContext());
2
Adstronomic.loadAndShow(this, rewardedAd);
Copied!
or
Java
1
AdstronomicAdsRewarded rewardedAd = new AdstronomicAdsRewarded(getApplicationContext());
2
rewardedAd.loadAd();
3
​
4
...
5
​
6
// Call when a button is pressed for example
7
if (rewardedAd.isAdLoaded()) {
8
rewardedAd.show();
9
}
Copied!

Listener

If you want to unlock reward or detect when an error occurred (ads not available because of internet connection issue), you can add a listener in order to execute your custom logic. For this, see the following example:
Java
1
AdListener listener = new AdListener() {
2
@Override
3
public void onAdLoadFailed(@NotNull Exception exception) {
4
​
5
}
6
​
7
@Override
8
public void onAdLoaded() {
9
​
10
}
11
​
12
@Override
13
public void onAdClosed() {
14
System.out.println("Event: onAdClosed");
15
}
16
​
17
@Override
18
public void onAdShown() {
19
​
20
}
21
​
22
@Override
23
public void onApplicationLeft() {
24
​
25
}
26
};
27
rewardedAd.setAdListener(listener);
Copied!
Each event is self explanatory. For example, if you want to give a reward to the player, execute this code in onAdClosed.
Copy link
Contents
Listener