| | |
| | | import com.bytedance.sdk.openadsdk.TTAdManager; |
| | | import com.bytedance.sdk.openadsdk.TTAdSdk; |
| | | import com.hanju.video.app.R; |
| | | import com.hanju.video.app.entity.ad.AdPositionEnum; |
| | | |
| | | /** |
| | | * 可以用一个单例来保存TTAdManager实例,在需要初始化sdk的时候调用 |
| | | */ |
| | | public class TTAdManagerHolder { |
| | | |
| | | private static boolean sInit; |
| | | |
| | | |
| | | public static TTAdManager get() { |
| | | if (!sInit) { |
| | | throw new RuntimeException("TTAdSdk is not init, please check."); |
| | | public static TTAdManager get() throws Exception { |
| | | if (!TTAdSdk.isInitSuccess()) { |
| | | throw new Exception("TTAdSdk is not init, please check."); |
| | | } |
| | | return TTAdSdk.getAdManager(); |
| | | } |
| | | |
| | | public static void init(Context context,String appId) { |
| | | doInit(context,appId); |
| | | public static void init(Context context, String appId, TTAdSdk.InitCallback initCallback) { |
| | | doInit(context, appId, initCallback); |
| | | } |
| | | |
| | | //step1:接入网盟广告sdk的初始化操作,详情见接入文档和穿山甲平台说明 |
| | | private static void doInit(Context context,String appId) { |
| | | if (!sInit) { |
| | | TTAdSdk.init(context, buildConfig(context,appId)); |
| | | sInit = true; |
| | | private static void doInit(Context context, String appId, TTAdSdk.InitCallback initCallback) { |
| | | if (!TTAdSdk.isInitSuccess()) { |
| | | TTAdSdk.init(context, buildConfig(context, appId), initCallback); |
| | | } else { |
| | | initCallback.success(); |
| | | } |
| | | } |
| | | |
| | | private static TTAdConfig buildConfig(Context context,String appId) { |
| | | return new TTAdConfig.Builder() |
| | | private static TTAdConfig buildConfig(Context context, String appId) { |
| | | |
| | | |
| | | TTAdConfig.Builder builder = new TTAdConfig.Builder() |
| | | .appId(appId) |
| | | .useTextureView(true) //使用TextureView控件播放视频,默认为SurfaceView,当有SurfaceView冲突的场景,可以使用TextureView |
| | | .appName(context.getString(R.string.app_name)) |
| | |
| | | .debug(true) //测试阶段打开,可以通过日志排查问题,上线时去除该调用 |
| | | .directDownloadNetworkType(TTAdConstant.NETWORK_STATE_WIFI, TTAdConstant.NETWORK_STATE_3G) //允许直接下载的网络状态集合 |
| | | .supportMultiProcess(true)//是否支持多进程 |
| | | .needClearTaskReset() |
| | | //.httpStack(new MyOkStack3())//自定义网络库,demo中给出了okhttp3版本的样例,其余请自行开发或者咨询工作人员。 |
| | | .build(); |
| | | .needClearTaskReset(); |
| | | //.httpStack(new MyOkStack3())//自定义网络库,demo中给出了okhttp3版本的样例,其余请自行开发或者咨询工作人员。 |
| | | if (AdUtil.getAdType(context, AdPositionEnum.splashHotStart) != null) { |
| | | builder.directDownloadNetworkType(TTAdConstant.NETWORK_STATE_WIFI); |
| | | } |
| | | |
| | | return builder.build(); |
| | | } |
| | | } |