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
unknown
plain_text
2 years ago
3.2 kB
3
Indexable
Never

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);

        UnityAds.initialize(context,GameID,testMode);

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

        banview.load();

        view = banview;

        linearLayout1.addView(view);


    }
    



    public static void showUnityInter(Context context){

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

            loadunityInterstrialAd();
    }



    public static void loadunityInterstrialAd(){

        if (UnityAds.isInitialized()){
            UnityAds.load(unityInterstitial);
        }

    }



    private static class UnityAdsListener implements IUnityAdsListener {


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

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

        @Override
        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.
        }

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




}