Second, let's connect an interstitial.
The initial setting is the same as the banner ad in the previous post.
2. Interstitial
Unlike banners, interstitials will display their screens according to the Google advertise sdk design at any timing, regardless of the current game screen. In other words, we will create a class separately for all elements because it is separate from the current user's view. (neatly)
1
2
3
4
|
public interface InterstitialService {
boolean isInterstitialLoaded();
void showInterstitial();
}
|
cs |
First add an interface to the core.
Implement this interface on android side.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
public class IntersitialAd implements InterstitialService {
Activity activity;
private InterstitialAd interstitialAd;
public IntersitialAd(Activity activity) {
this.activity = activity;
interstitialAd = new InterstitialAd(this.activity);
interstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712"); //google intersititial test id
interstitialAd.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {}
@Override
public void onAdClosed() {
loadIntersitialAd();
}
});
loadIntersitialAd();
}
private void loadIntersitialAd(){
AdRequest interstitialRequest = new AdRequest.Builder().build();
interstitialAd.loadAd(interstitialRequest);
}
@Override
public boolean isInterstitialLoaded() {
return interstitialAd.isLoaded();
}
@Override
public void showInterstitial() {
}
}
|
cs |
Initialize and load a new interstitial with loadIntersitialAd (). And onAdClosed, the code that loads a new interstitial when the interstitial finishes and closes.
Here is what the ad shows.
1
2
3
4
5
6
7
8
9
10
11
12
|
@Override
public void showInterstitial() {
activity.runOnUiThread(new Runnable() {
public void run() {
if (interstitialAd.isLoaded()) {
interstitialAd.show();
}else {
loadIntersitialAd();
}
}
});
}
|
cs |
If the interstitial is loaded, run show (), or else load it again. This part runs in a new thread.
Add this part to MyGdxGame.


It's done Now let's decide when to run the ad.
When the loading screen is in progress, we will stop the 50% progress and run the interstitial.
We will modify the loading data of the previous example to get 10 data.
(If the data is too small, it may not run.)


We've added a flag to only run once if it's 50% or higher.

'Etc' 카테고리의 다른 글
Jmonkey base scene initialize (sdk) (0) | 2019.12.03 |
---|---|
adMob - reward, libgdx (0) | 2019.11.30 |
adMob - banner, libgdx (0) | 2019.11.23 |
카메라 lookAt 함수의 이용 - 예제, 활용법(example, how to) (1) | 2019.11.12 |
카메라 lookAt 함수의 이용 - Yaw, Pitch, Roll (0) | 2019.11.12 |
댓글