package com.sound;

import android.app.Application;
import android.content.Context;
import android.content.Intent;

import androidx.localbroadcastmanager.content.LocalBroadcastManager;

import com.applovin.sdk.AppLovinMediationProvider;
import com.applovin.sdk.AppLovinSdk;
import com.applovin.sdk.AppLovinSdkConfiguration;
import com.applovin.sdk.AppLovinSdkInitializationConfiguration;

public class MainApplication extends Application {
    /**
     * 全局的上下文
     */
    private static Context mContext;

    public static final String TAG = "--------------";
    public static final String AD_BROADCAST = "on_success_action";
    private static final String MAX_SDK = "i4k2zRVkJrBdZ2AlcVyiG2B1feL1OvMldT2ea5279uyuoGXtC_5uGTbx7Up_JehNT_K0TmZK42hpEAFFwlHLEb";
    public static Boolean initSDK = false;


    @Override
    public void onCreate() {
        super.onCreate();
        //获取应用的上下文并赋值给 mContext
        mContext = getApplicationContext();

        initSdk();

    }

    /**
     * 获取context
     *
     * @return
     */
    public static Context getContext() {
        return mContext;
    }

    //重写 onLowMemory 方法，在系统内存不足时调用。这里只是调用了父类的 onLowMemory 方法，没有做其他处理
    @Override
    public void onLowMemory() {
        super.onLowMemory();
    }


    private void initSdk() {

        AppLovinSdkInitializationConfiguration initConfig = AppLovinSdkInitializationConfiguration.builder(MAX_SDK, this)
                .setMediationProvider(AppLovinMediationProvider.MAX)
                .build();
        AppLovinSdk.getInstance(this).initialize(initConfig, new AppLovinSdk.SdkInitializationListener() {
            @Override
            public void onSdkInitialized(final AppLovinSdkConfiguration sdkConfig) {
                initSDK = true;
                LocalBroadcastManager.getInstance(mContext).sendBroadcast(new Intent(AD_BROADCAST));
            }
        });
        AppLovinSdk.getInstance(this).getSettings().setVerboseLogging(true);
        //MAX广告测试
//        AppLovinSdk.getInstance( this ).showMediationDebugger();

    }

}
