others-Vungle广告接入
others-Vungle广告接入
前篇
- 官方 - https://liftoff.io/
接入
gradle 引入 sdk
1
implementation 'com.vungle:vungle-ads:7.3.1'
插页式广告
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89package com.animalslots.misc;
import android.app.Activity;
//import com.google.android.gms.ads.AdError;
//import com.google.android.gms.ads.AdRequest;
//import com.google.android.gms.ads.FullScreenContentCallback;
//import com.google.android.gms.ads.LoadAdError;
//import com.google.android.gms.ads.interstitial.InterstitialAd;
//import com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback;
import androidx.annotation.NonNull;
import com.google.android.gms.ads.AdError;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.FullScreenContentCallback;
import com.google.android.gms.ads.LoadAdError;
import com.google.android.gms.ads.interstitial.InterstitialAd;
import com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback;
import com.vungle.ads.AdConfig;
import com.vungle.ads.BaseAd;
import com.vungle.ads.BaseAdListener;
import com.vungle.ads.InitializationListener;
import com.vungle.ads.VungleAds;
import com.vungle.ads.VungleError;
public class AdsHelper {
// --------------- Vungle 实现
private static class AdVungle {
private static String APPID = "6618f0c7d4cf07f3aaaaaa";
private static String INTERID = "bbbbbbbb-123123123";
public void show(Activity activity, Tool.CodeRunnable task) {
VungleAds.init(activity, APPID, new InitializationListener() {
public void onSuccess() {
com.vungle.ads.InterstitialAd interstitialAd = new com.vungle.ads.InterstitialAd(activity, INTERID, new AdConfig());
interstitialAd.setAdListener(new BaseAdListener() {
public void onAdLoaded( BaseAd baseAd){
SplashHelper.getIns().HideSplash("");
interstitialAd.play(activity);
}
public void onAdStart( BaseAd baseAd){
}
public void onAdImpression( BaseAd baseAd){
}
public void onAdEnd( BaseAd baseAd){
task.run(1, String.format("Ad onAdEnd"));
}
public void onAdClicked( BaseAd baseAd){
}
public void onAdLeftApplication( BaseAd baseAd){
}
public void onAdFailedToLoad( BaseAd baseAd, VungleError vungleError){
task.run(-2, String.format("onAdFailedToLoad"));
}
public void onAdFailedToPlay( BaseAd baseAd, VungleError vungleError){
task.run(-2, String.format("onAdFailedToPlay"));
}
});
interstitialAd.load(null);
}
public void onError( VungleError vungleError){
task.run(-2, String.format("onError"));
}
});
}
}
}广告改为 测试模式
广告先 deactivate 再 active, 不然可能出现换参数后广告不生效