others-Vungle广告接入

others-Vungle广告接入


前篇


接入

  1. gradle 引入 sdk

    1
    implementation 'com.vungle:vungle-ads:7.3.1'
  2. 插页式广告

    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
    89
    package 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";

    @Override
    public void show(Activity activity, Tool.CodeRunnable task) {
    VungleAds.init(activity, APPID, new InitializationListener() {
    @Override
    public void onSuccess() {
    com.vungle.ads.InterstitialAd interstitialAd = new com.vungle.ads.InterstitialAd(activity, INTERID, new AdConfig());
    interstitialAd.setAdListener(new BaseAdListener() {
    @Override
    public void onAdLoaded(@NonNull BaseAd baseAd) {
    SplashHelper.getIns().HideSplash("");
    interstitialAd.play(activity);
    }

    @Override
    public void onAdStart(@NonNull BaseAd baseAd) {
    }

    @Override
    public void onAdImpression(@NonNull BaseAd baseAd) {
    }

    @Override
    public void onAdEnd(@NonNull BaseAd baseAd) {
    task.run(1, String.format("Ad onAdEnd"));
    }

    @Override
    public void onAdClicked(@NonNull BaseAd baseAd) {
    }

    @Override
    public void onAdLeftApplication(@NonNull BaseAd baseAd) {
    }

    @Override
    public void onAdFailedToLoad(@NonNull BaseAd baseAd, @NonNull VungleError vungleError) {
    task.run(-2, String.format("onAdFailedToLoad"));
    }

    @Override
    public void onAdFailedToPlay(@NonNull BaseAd baseAd, @NonNull VungleError vungleError) {
    task.run(-2, String.format("onAdFailedToPlay"));
    }
    });
    interstitialAd.load(null);
    }

    @Override
    public void onError(@NonNull VungleError vungleError) {
    task.run(-2, String.format("onError"));
    }
    });
    }
    }
    }
  3. 广告改为 测试模式

    image-20240415162318056

  4. 广告先 deactivate 再 active, 不然可能出现换参数后广告不生效

    image-20240415162555767