Commit 8bbef7e3 authored by mengcuiguang's avatar mengcuiguang

添加开屏

parent ba384c21
......@@ -132,7 +132,7 @@
<!-- </activity>-->
<activity
android:name=".ui.activitys.SplashYlhActivity"
android:name=".ui.activitys.SplashGroMoreActivity"
android:screenOrientation="portrait"
android:theme="@style/NormalSplash">
<intent-filter>
......
package com.mints.goodmoney.ui.activitys;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.widget.FrameLayout;
import com.bytedance.msdk.adapter.pangle.PangleNetworkRequestInfo;
import com.bytedance.msdk.adapter.util.Logger;
import com.bytedance.msdk.api.AdError;
import com.bytedance.msdk.api.AdSlot;
import com.bytedance.msdk.api.NetworkPlatformConst;
import com.bytedance.msdk.api.TTNetworkRequestInfo;
import com.bytedance.msdk.api.splash.TTSplashAd;
import com.bytedance.msdk.api.splash.TTSplashAdListener;
import com.bytedance.msdk.api.splash.TTSplashAdLoadCallback;
import com.mints.goodmoney.MintsApplication;
import com.mints.goodmoney.R;
import com.mints.goodmoney.common.Constant;
import com.mints.goodmoney.common.DeviceInfo;
import com.mints.goodmoney.manager.TrackManager;
import com.mints.goodmoney.manager.TtCsjAdManager;
import com.mints.goodmoney.manager.UserManager;
import com.mints.goodmoney.ui.activitys.base.BaseActivity;
import com.mints.goodmoney.utils.LogUtil;
import com.mints.library.utils.CommonUtils;
import com.yilan.sdk.ui.little.YLLittleVideoFragment;
import net.grandcentrix.tray.AppPreferences;
/**
* GroMore开屏广告Activity示例
*/
public class SplashGroMoreActivity extends BaseActivity {
private static final String TAG = "SplashGroMoreActivity";
private TTSplashAd mTTSplashAd;
private FrameLayout mSplashContainer;
//是否强制跳转到主页面
private boolean mForceGoMain;
private String mAdUnitId = "887459392";
//开屏广告加载超时时间,建议大于1000,这里为了冷启动第一次加载到广告并且展示,示例设置了2000ms
private static final int AD_TIME_OUT = 4000;
private static final int MSG_GO_MAIN = 1;
//开屏广告是否已经加载
private boolean mHasLoaded;
// 百度开屏广告点击跳转落地页后倒计时不暂停,即使在看落地页,倒计时结束后仍然会强制跳转,需要特殊处理:
// 检测到广告被点击,且走了activity的onPaused证明跳转到了落地页,这时候onAdDismiss回调中不进行跳转,而是在activity的onResume中跳转。
private boolean isBaiduSplashAd = false;
private boolean baiduSplashAdClicked = false;
private boolean onPaused = false;
private AppPreferences ps;
/**
* 加载开屏广告
*/
private void loadSplashAd() {
if (mAdUnitId == null) return;
/**
* 注:每次加载开屏广告的时候需要新建一个TTSplashAd,否则可能会出现广告填充问题
* ( 例如:mTTSplashAd = new TTSplashAd(this, mAdUnitId);)
*/
mTTSplashAd = new TTSplashAd(this, mAdUnitId);
mTTSplashAd.setTTAdSplashListener(mSplashAdListener);
//step3:创建开屏广告请求参数AdSlot,具体参数含义参考文档
AdSlot adSlot = new AdSlot.Builder()
.setImageAdSize(1080, 1920) // 既适用于原生类型,也适用于模版类型。
.build();
//自定义兜底方案 选择使用
TTNetworkRequestInfo ttNetworkRequestInfo;
//穿山甲兜底
ttNetworkRequestInfo = new PangleNetworkRequestInfo(TtCsjAdManager.TT_AD_APPID, "887459392");
//gdt兜底
// ttNetworkRequestInfo = new GdtNetworkRequestInfo("1101152570", "8863364436303842593");
//ks兜底
// ttNetworkRequestInfo = new KsNetworkRequestInfo("90009", "4000000042");
//百度兜底
// ttNetworkRequestInfo = new BaiduNetworkRequestInfo("e866cfb0", "2058622");
//step4:请求广告,调用开屏广告异步请求接口,对请求回调的广告作渲染处理
mTTSplashAd.loadAd(adSlot, ttNetworkRequestInfo, new TTSplashAdLoadCallback() {
@Override
public void onSplashAdLoadFail(AdError adError) {
LogUtil.d(TAG, adError.message);
mHasLoaded = true;
Log.e(TAG, "load splash ad error : " + adError.code + ", " + adError.message);
// 获取本次waterfall加载中,加载失败的adn错误信息。
if (mTTSplashAd != null)
LogUtil.d(TAG, "ad load infos: " + mTTSplashAd.getAdLoadInfoList());
goToMainActivity();
}
@Override
public void onSplashAdLoadSuccess() {
if (mTTSplashAd != null) {
mTTSplashAd.showAd(mSplashContainer);
isBaiduSplashAd = mTTSplashAd.getAdNetworkPlatformId() == NetworkPlatformConst.SDK_NAME_BAIDU;
// 获取本次waterfall加载中,加载失败的adn错误信息。
if (mTTSplashAd != null)
LogUtil.d(TAG, "ad load infos: " + mTTSplashAd.getAdLoadInfoList());
}
Log.e(TAG, "load splash ad success ");
}
@Override
public void onAdLoadTimeout() {
mHasLoaded = true;
showToast("开屏广告加载超时");
Log.i(TAG, "开屏广告加载超时.......");
// 获取本次waterfall加载中,加载失败的adn错误信息。
if (mTTSplashAd != null)
LogUtil.d(TAG, "ad load infos: " + mTTSplashAd.getAdLoadInfoList());
goToMainActivity();
}
}, AD_TIME_OUT);
}
TTSplashAdListener mSplashAdListener = new TTSplashAdListener() {
@Override
public void onAdClicked() {
baiduSplashAdClicked = true;
showToast("开屏广告被点击");
LogUtil.d(TAG, "onAdClicked");
}
@Override
public void onAdShow() {
showToast("开屏广告展示");
LogUtil.d(TAG, "onAdShow");
}
@Override
public void onAdSkip() {
showToast("开屏广告点击跳过按钮");
LogUtil.d(TAG, "onAdSkip");
goToMainActivity();
}
@Override
public void onAdDismiss() {
showToast("开屏广告倒计时结束关闭");
LogUtil.d(TAG, "onAdDismiss");
if (isBaiduSplashAd && onPaused && baiduSplashAdClicked) {
// 这种情况下,百度开屏广告不能在onAdDismiss中跳转,需要在onResume中跳转主页。
return;
}
goToMainActivity();
}
};
@Override
protected void onResume() {
//判断是否该跳转到主页面
if (mForceGoMain) {
goToMainActivity();
}
if (isBaiduSplashAd && onPaused && baiduSplashAdClicked) {
// 这种情况下,百度开屏广告不能在onAdDismiss中跳转,需要自己在onResume中跳转主页。
goToMainActivity();
}
super.onResume();
}
@Override
protected void onPause() {
super.onPause();
onPaused = true;
}
@Override
protected void onStop() {
super.onStop();
mForceGoMain = true;
}
@Override
protected void onDestroy() {
super.onDestroy();
if (mTTSplashAd != null) {
mTTSplashAd.destroy();
}
}
@Override
protected int getContentViewLayoutID() {
return R.layout.activity_splash_gromore;
}
@Override
protected void initViewsAndEvents() {
if (!isTaskRoot()) {
//点击Home键后再点击App图标,会回到原来的界面。今天重新打包后,但是在Debug模式下,一切正常,
// 但是把打完包的apk(Release)安装在其他手机上时,回到桌面后点击图标会重新打开启动页
finish();
return;
}
TrackManager.getInstance().getCommonHallBaseMsg();
TrackManager.getInstance().firstApiWithUid();
// 校验APP签名
checkAppSign();
}
/**
* 校验App签名
*/
private void checkAppSign() {
DeviceInfo deviceInfo = DeviceInfo.Companion.getInstance();
if (!deviceInfo.getSignInfo()) {
getBaseApplication().exitApp();
} else {
YLLittleVideoFragment.preloadVideo();
try {
mSplashContainer = findViewById(R.id.splash_container);
ps = new AppPreferences(this);
//加载开屏广告
loadSplashAd();
} catch (Exception e) {
goToMainActivity();
}
}
}
@Override
protected boolean isApplyKitKatTranslucency() {
return false;
}
/**
* 跳转到主页面
*/
private void goToMainActivity() {
int customVersion = ps.getInt(Constant.CUSTOM_VERSION, 0);
boolean isFirstEnter = ps.getBoolean(Constant.ISFIRSTENTER + customVersion, true);
if (isFirstEnter) {
readyGoThenKill(GuideActivity.class);
} else {
String channel = CommonUtils.getAppMetaData(MintsApplication.getContext(), "CHANNEL_NAME");
if (TextUtils.equals(channel, Constant.CHANNEL_SHARE) && !UserManager.getInstance().userIsLogin()) {
readyGo(WxLoginActivity.class);
} else {
readyGoThenKill(MainActivity.class);
}
}
mSplashContainer.removeAllViews();
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
return true;
}
return super.onKeyDown(keyCode, event);
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:orientation="vertical">
<FrameLayout
android:id="@+id/splash_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"></FrameLayout>
</LinearLayout>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment