package com.ysvideo.zhibo.library_ad;
|
|
import android.content.Context;
|
import android.content.SharedPreferences;
|
import android.os.Build;
|
|
import com.bytedance.sdk.openadsdk.TTAdSdk;
|
import com.ysvideo.zhibo.lib.common.util.common.StringUtils;
|
import com.qq.e.comm.managers.GDTAdSdk;
|
|
import org.json.JSONException;
|
import org.json.JSONObject;
|
|
public class AdUtil {
|
|
public enum AD_TYPE {
|
gdt("广点通"), csj("穿山甲");
|
private String name;
|
|
AD_TYPE(String name) {
|
this.name = name;
|
}
|
}
|
|
|
/**
|
* 初始化广点通广告
|
*
|
* @param context
|
* @param appId
|
*/
|
public static void initGDTAd(Context context, String appId) {
|
GDTAdSdk.init(context, appId);
|
}
|
|
/**
|
* 穿山甲广告初始化
|
*
|
* @param context
|
* @param appId
|
* @param downLoadNotify
|
* @param initCallback
|
*/
|
public static void initCSJAd(Context context, String appId, boolean downLoadNotify, TTAdSdk.InitCallback initCallback) {
|
TTAdManagerHolder.init(context, appId, downLoadNotify, initCallback);
|
}
|
|
|
/**
|
* 保存广告配置
|
*
|
* @param context
|
* @param json
|
*/
|
public static void saveAdConfig(Context context, JSONObject json) {
|
SharedPreferences share = context.getSharedPreferences("adConfig", Context.MODE_PRIVATE);
|
SharedPreferences.Editor editor = share.edit();
|
editor.putString("config", json.toString());
|
editor.commit();
|
}
|
|
/**
|
* 获取广告类型
|
*
|
* @param context
|
* @param positionName
|
* @return
|
*/
|
public static AD_TYPE getAdType(Context context, String positionName) {
|
SharedPreferences share = context.getSharedPreferences("adConfig", Context.MODE_PRIVATE);
|
String config = share.getString("config", "");
|
if (!StringUtils.isEmpty(config)) {//万一没设置起就用广点通
|
try {
|
JSONObject object = new JSONObject(config);
|
return AD_TYPE.valueOf(object.optJSONObject(positionName).optString("type"));
|
} catch (JSONException e) {
|
e.printStackTrace();
|
} catch (Exception e1) {
|
return null;
|
}
|
}
|
return null;
|
}
|
|
public static boolean isCanInitCSJ() {
|
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
|
}
|
|
}
|