unity ads initialize failed

I create this UnityAd class and the calling in the kotlin MainActivity like this UnityAd.loadunityInterstrialAd() UnityAd.showUnityInter(this)
mail@pastecode.io avatar
2 years ago
3.2 kB

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;

import com.leaftorrent_magneticlinks.torrent_search_engine.R;
import com.unity3d.ads.BuildConfig;
import com.unity3d.ads.IUnityAdsListener;
import com.unity3d.ads.UnityAds;
import com.unity3d.services.banners.BannerErrorInfo;
import com.unity3d.services.banners.BannerView;
import com.unity3d.services.banners.UnityBannerSize;

public class UnityAd {
    private static final String TAG = "UnityAds";
    private static Context context;
    public static UnityAd store;

    private static final String GameID = "4300729";
    private static final String bannerPlacement = "Banner_Android";
    private static final Boolean testMode = true;
    private static final String  unityInterstitial = "Interstitial_Android";

    private static  RelativeLayout linearLayout;

    static  Activity activity;

    public static void showBannerUnity(Context context, View view){

        RelativeLayout linearLayout1 = view.findViewById(R.id.bannerLayout);


        BannerView banview = new BannerView((Activity) context, bannerPlacement,new UnityBannerSize(320,50));


        view = banview;



    public static void showUnityInter(Context context){

            UnityAds.show((Activity) context,unityInterstitial);


    public static void loadunityInterstrialAd(){

        if (UnityAds.isInitialized()){


    private static class UnityAdsListener implements IUnityAdsListener {

        public void onUnityAdsReady(String placementId) {
            // Implement functionality for an ad being ready to show.

        public void onUnityAdsStart(String placementId) {
            // Implement functionality for a user starting to watch an ad.

        public void onUnityAdsFinish(String placementId, com.unity3d.ads.UnityAds.FinishState finishState) {
            if (finishState.equals(UnityAds.FinishState.COMPLETED)) {
                // Reward the user for watching the ad to completion.
            } else if (finishState.equals(UnityAds.FinishState.SKIPPED)) {
                // Do not reward the user for skipping the ad.
            } else if (finishState.equals(UnityAds.FinishState.ERROR)) {
                // Log an error.
            // Implement functionality for a user finishing an ad.

        public void onUnityAdsError(com.unity3d.ads.UnityAds.UnityAdsError error, String message) {
            // Implement functionality for a Unity Ads service error occurring.