package com.reactlibrary.uMeng;

import android.app.Activity;
import android.app.Application;

import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.umeng.commonsdk.UMConfigure;
import com.umeng.message.PushAgent;

import javax.annotation.Nonnull;

import androidx.annotation.NonNull;

public class UmCommon extends ReactContextBaseJavaModule {

    private static ReactApplicationContext reactContext;
    public static UmCommon instance;
    public static Application application;
    public static Activity activity;

    public static void setApp(Application app){
        application = app;
    }

    public static void setActivity(Activity ac){
        activity = ac;
    }

    @NonNull
    @Override
    public String getName() {
        return "UmCommon";
    }

    public UmCommon(@Nonnull ReactApplicationContext context) {
        super(context);
        reactContext = context;
        instance = this;
    }

    @ReactMethod
    public void initWithAppkey(String appkey, String channel, Boolean debug, String pushSecret) {
        UMConfigure.setLogEnabled(debug);
        UMConfigure.init(reactContext, appkey, channel, UMConfigure.DEVICE_TYPE_PHONE, pushSecret);
//        该方法是【友盟+】Push后台进行日活统计及多维度推送的必调用方法，请务必调用！
        PushAgent.getInstance(application).onAppStart();
//        为了便于开发者更好的集成配置文件，我们提供了对于AndroidManifest配置文件的检查工具，可以自行检查开发者的配置问题。SDK默认是不检查集成配置文件的。自定义检查集成配置文件的接口如下
        PushAgent.getInstance(application).setPushCheck(true);

    }




}
