|
|
@@ -2,28 +2,21 @@ package com.sheep.gamegroup.view.activity;
|
|
|
|
|
|
import android.Manifest;
|
|
|
import android.content.pm.PackageManager;
|
|
|
-import android.os.Bundle;
|
|
|
import android.os.Environment;
|
|
|
-import android.support.annotation.Nullable;
|
|
|
import android.support.v4.app.ActivityCompat;
|
|
|
import android.support.v4.content.ContextCompat;
|
|
|
-import android.view.View;
|
|
|
+import android.util.Log;
|
|
|
import android.widget.FrameLayout;
|
|
|
import android.widget.TextView;
|
|
|
-import android.widget.Toast;
|
|
|
-import com.jasmine.cantaloupe.engine.SplashEngine;
|
|
|
import com.jasmine.cantaloupe.ui.widget.AdFrameLayout;
|
|
|
-import com.lygame.wrapper.ad.LySplashAdBuilder;
|
|
|
-import com.lygame.wrapper.interfaces.*;
|
|
|
-import com.lygame.wrapper.sdk.LySdk;
|
|
|
+import com.sheep.gamegroup.absBase.BaseActivity;
|
|
|
import com.sheep.gamegroup.util.FileUtil;
|
|
|
import com.sheep.jiuyan.samllsheep.R;
|
|
|
-import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
import com.sheep.jiuyan.samllsheep.utils.G;
|
|
|
-import com.tencent.klevin.KleinManager;
|
|
|
-import com.tencent.klevin.base.callback.KleinResponseCallback;
|
|
|
-import com.tencent.klevin.base.view.BaseActivity;
|
|
|
-import com.tencent.klevin.util.AdUtils;
|
|
|
+import com.tencent.klevin.ads.ad.RewardAd;
|
|
|
+import com.tencent.klevin.ads.ad.RewardAdRequest;
|
|
|
+import com.tencent.klevin.ads.ad.SplashAd;
|
|
|
+import com.tencent.klevin.ads.ad.SplashAdRequest;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
@@ -31,9 +24,6 @@ import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
-import java.util.concurrent.atomic.AtomicReference;
|
|
|
-
|
|
|
-import static com.tencent.klevin.base.okhttp.ErrorCode.*;
|
|
|
|
|
|
/**
|
|
|
* @Author: ZEKI https://github.com/ZYF99
|
|
|
@@ -41,49 +31,43 @@ import static com.tencent.klevin.base.okhttp.ErrorCode.*;
|
|
|
*/
|
|
|
public class DataGoAct extends BaseActivity {
|
|
|
|
|
|
-
|
|
|
FrameLayout zk_root;
|
|
|
AdFrameLayout flSplashYT;
|
|
|
TextView yt_splash_skip_view;
|
|
|
|
|
|
- String dataFileName;
|
|
|
- String sdCardFileName;
|
|
|
+ String successCountLogFileName;
|
|
|
+ String eventLogFileName;
|
|
|
+ private String TAG = "DataGoAct";
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected int getLayoutId() {
|
|
|
+ return R.layout.act_data_go;
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
- public void onCreate(@Nullable @org.jetbrains.annotations.Nullable Bundle bundle) {
|
|
|
- super.onCreate(bundle);
|
|
|
- setContentView(R.layout.act_data_go);
|
|
|
+ public void initView() {
|
|
|
requestPermissions();
|
|
|
zk_root = findViewById(R.id.zk_root);
|
|
|
flSplashYT = findViewById(R.id.fv_splash_yt);
|
|
|
yt_splash_skip_view = findViewById(R.id.splash_skip_view);
|
|
|
- findViewById(R.id.btn_yky_splash).setOnClickListener(v -> {
|
|
|
- launchYKYSplash();
|
|
|
- });
|
|
|
- findViewById(R.id.btn_yt_splash).setOnClickListener(v -> {
|
|
|
- launchYTSplash();
|
|
|
- });
|
|
|
- findViewById(R.id.btn_zk_splash).setOnClickListener(v -> {
|
|
|
- launchZKSplash();
|
|
|
- });
|
|
|
- findViewById(R.id.btn_yky_courage).setOnClickListener(v -> {
|
|
|
- showYKYCourage();
|
|
|
- });
|
|
|
- findViewById(R.id.btn_zk_courage).setOnClickListener(v -> {
|
|
|
- showZKCourage();
|
|
|
- });
|
|
|
+ findViewById(R.id.btn_yky_splash).setOnClickListener(v -> launchYKYSplash());
|
|
|
+ findViewById(R.id.btn_yky_courage).setOnClickListener(v -> showYKYCourage());
|
|
|
+ initLog();
|
|
|
+ }
|
|
|
|
|
|
- dataFileName = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "backUPFiles" + File.separator + "YKYSuccessLog" + ".txt";
|
|
|
- sdCardFileName = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "backUPFiles" + File.separator + "YKYEventLog" + ".txt";
|
|
|
- File dataFile = new File(dataFileName);
|
|
|
- File sdcardFile = new File(sdCardFileName);
|
|
|
+ //日志文件准备工作
|
|
|
+ void initLog() {
|
|
|
+ File dir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "backUPFiles");
|
|
|
+ if (!dir.exists()) {
|
|
|
+ dir.mkdirs();
|
|
|
+ }
|
|
|
+ successCountLogFileName = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "backUPFiles" + File.separator + "YKYSuccessLog.txt";
|
|
|
+ eventLogFileName = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "backUPFiles" + File.separator + "YKYEventLog.txt";
|
|
|
+ File dataFile = new File(successCountLogFileName);
|
|
|
+ File sdcardFile = new File(eventLogFileName);
|
|
|
try {
|
|
|
- if (!dataFile.exists()) {
|
|
|
- dataFile.createNewFile();
|
|
|
- }
|
|
|
- if (!sdcardFile.exists()) {
|
|
|
- sdcardFile.createNewFile();
|
|
|
- }
|
|
|
+ if (!dataFile.exists()) dataFile.createNewFile();
|
|
|
+ if (!sdcardFile.exists()) sdcardFile.createNewFile();
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
@@ -91,321 +75,185 @@ public class DataGoAct extends BaseActivity {
|
|
|
//标记开启
|
|
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
String dateStr = simpleDateFormat.format(new Date());
|
|
|
- FileUtil.addContentToFile(dataFileName, "\n\n\n" + dateStr + "\n");
|
|
|
- FileUtil.addContentToFile(sdCardFileName, "\n\n\n" + dateStr + "\n");
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- //请求权限
|
|
|
- public boolean requestPermissions() {
|
|
|
- List<String> permissions = new ArrayList<>();
|
|
|
- boolean result = true;
|
|
|
- if (ContextCompat.checkSelfPermission(
|
|
|
- this,
|
|
|
- Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
|
|
- permissions.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
|
|
- permissions.add(Manifest.permission.READ_EXTERNAL_STORAGE);
|
|
|
- result = false;
|
|
|
- }
|
|
|
- if (permissions.size() > 0) {
|
|
|
- String[] permissionArrays = new String[permissions.size()];
|
|
|
- permissionArrays = permissions.toArray(permissionArrays);
|
|
|
- ActivityCompat.requestPermissions(this, permissionArrays, 1111);
|
|
|
- }
|
|
|
- return result;
|
|
|
+ FileUtil.addContentToFile(successCountLogFileName, "\n\n\n" + dateStr + "\n");
|
|
|
+ FileUtil.addContentToFile(eventLogFileName, "\n\n\n" + dateStr + "\n");
|
|
|
}
|
|
|
|
|
|
+ //开屏展示总量
|
|
|
int splashTotalCount = 0;
|
|
|
+
|
|
|
+ //开屏展示成功数
|
|
|
int splashSuccessCount = 0;
|
|
|
|
|
|
+ //视频展示总量
|
|
|
int videoTotalCount = 0;
|
|
|
+
|
|
|
+ //视频展示成功数
|
|
|
int videoSuccessCount = 0;
|
|
|
|
|
|
//展示游可盈广告
|
|
|
+ SplashAd mSplashAd;
|
|
|
+
|
|
|
private void launchYKYSplash() {
|
|
|
|
|
|
splashTotalCount++;
|
|
|
- FileUtil.addContentToFile(dataFileName, "YKY splash total:" + splashTotalCount + "\n");
|
|
|
-
|
|
|
- String data = "{\"placements\":[{\"pos_id\":" + 30112 + ",\"ad_count\":1}]}";
|
|
|
- //"{\"placements\":[{\"pos_id\":" + posId + ",\"ad_count\":1}]}";
|
|
|
- KleinManager.getInstance().prepareAD(
|
|
|
- getApplicationContext(),
|
|
|
- data,
|
|
|
- 5000,
|
|
|
- true,
|
|
|
- new KleinResponseCallback() {
|
|
|
- @Override
|
|
|
- public void onSuccess(int i) {
|
|
|
- G.showToast("游可盈-onSuccess" + i + "\n");
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onFail(int i) {
|
|
|
- FileUtil.addContentToFile(sdCardFileName, "YKY splash onFail:" + i + "\n");
|
|
|
- //拉取广告错误或超时,直接跳过
|
|
|
- G.showToast("游可盈-onFail" + i);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onEvent(int i) {
|
|
|
- FileUtil.addContentToFile(sdCardFileName, "YKY splash onEvent:" + i + "\n");
|
|
|
- switch (i) {
|
|
|
- case KLSplashAdEvent_AdShowSucc:
|
|
|
- G.showToast("游可盈-广告展示成功");
|
|
|
- splashSuccessCount++;
|
|
|
- FileUtil.addContentToFile(dataFileName, "开屏成功数:" + splashSuccessCount + "\n");
|
|
|
- break;
|
|
|
- case KLSplashAdEvent_AdTap:
|
|
|
- G.showToast("游可盈-点击广告");
|
|
|
- break;
|
|
|
- case KLSplashAdEvent_AdPlayCompletion:
|
|
|
- case KLSplashAdEvent_AdShowFinish:
|
|
|
- case KLSplashAdEvent_AdSkip:
|
|
|
- G.showToast("游可盈-跳过广告");
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
- //展示游可盈video
|
|
|
- private void showYKYCourage() {
|
|
|
- preAd(true);
|
|
|
- }
|
|
|
-
|
|
|
- //预加载video
|
|
|
- private void preAd(boolean shouldShow) {
|
|
|
-
|
|
|
- videoTotalCount++;
|
|
|
- FileUtil.addContentToFile(dataFileName, "YKY video total:" + videoTotalCount + "\n");
|
|
|
-
|
|
|
- int posId = 30113;
|
|
|
- int duration = 0;
|
|
|
- //String data = "{\"placements\":[{\"pos_id\":" + posId + ",\"ad_count\":" + releaseTask.getTask().getVideo_num() + "}],\"ad_reward_trigger\":1, \"ad_reward_duration\":" + duration + ", \"ad_reward_automute\":1}";
|
|
|
- String data = "{\"placements\":[{\"pos_id\":" + posId + ",\"ad_count\":1}],\"ad_reward_trigger\":1, \"ad_reward_duration\":" + duration + ", \"ad_reward_automute\":1}";
|
|
|
+ FileUtil.addContentToFile(successCountLogFileName, "YKY splash total count:" + splashTotalCount + "\n");
|
|
|
|
|
|
- KleinManager.getInstance().loadEncourageAD(SheepApp.getInstance().getApplicationContext(), data, new KleinResponseCallback() {
|
|
|
+ SplashAdRequest.Builder splashAdBuilder = new SplashAdRequest.Builder();
|
|
|
+ splashAdBuilder.setWaitTime(3500)// 【可选】默认不限制,可传值范围[3000-5000]
|
|
|
+ .setAdCount(1)//【可选】广告个数,默认 1
|
|
|
+ .setPosId(30112);//【必须】开屏广告位 id 正式30112 测试30029
|
|
|
|
|
|
- @Override
|
|
|
- public void onSuccess(int i) {
|
|
|
- handleSuccess(i, shouldShow);
|
|
|
+ //开屏广告加载回调
|
|
|
+ SplashAd.load(splashAdBuilder.build(), new SplashAd.SplashAdLoadListener() {
|
|
|
+ public void onTimeOut() { //加载超时 Log.e(TAG, "splash ad load timeout");
|
|
|
+ FileUtil.addContentToFile(eventLogFileName, "YKY splash onTimeOut" + "\n");
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void onFail(int i) {
|
|
|
- G.showToast("游可盈video 加载onFail" + i);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onEvent(int i) {
|
|
|
- G.showToast("游可盈video 加载onEvent" + i);
|
|
|
- handleEvent(i);
|
|
|
+ public void onAdLoadError(int err, String msg) {
|
|
|
+ // 加载失败,err 是错误码,msg 是描述信息
|
|
|
+ Log.e(TAG, "splash ad load err: " + err + " " + msg);
|
|
|
+ G.showToast("游可盈开屏-加载错误" + err);
|
|
|
+ FileUtil.addContentToFile(eventLogFileName, "YKY splash error:" + err + "\n");
|
|
|
}
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- //播放video
|
|
|
- private void showAd() {
|
|
|
- KleinManager.getInstance().showAD(DataGoAct.this, AdUtils.TYPE_AD_REWARD,
|
|
|
- new KleinResponseCallback() {
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onSuccess(int i) {
|
|
|
-
|
|
|
- handleSuccess(i, false);
|
|
|
- }
|
|
|
|
|
|
- @Override
|
|
|
- public void onFail(int i) {
|
|
|
- FileUtil.addContentToFile(sdCardFileName, "YKY video onFail:" + i + "\n");
|
|
|
- G.showToast("游可盈video onFail" + i);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onEvent(int i) {
|
|
|
- FileUtil.addContentToFile(sdCardFileName, "YKY video onEvent:" + i + "\n");
|
|
|
- if (i == KLSplashAdEvent_AdShowSucc) {
|
|
|
- videoSuccessCount++;
|
|
|
- FileUtil.addContentToFile(dataFileName, "YKY video success count:" + videoSuccessCount + "\n");
|
|
|
+ public void onAdLoaded(SplashAd adTmp) {//加载成功,ad 为开屏广告实例 Log.i(TAG, "splash ad loaded");
|
|
|
+ mSplashAd = adTmp;
|
|
|
+ if (mSplashAd != null) {
|
|
|
+ //设置开屏广告展示回调
|
|
|
+ mSplashAd.setListener(new SplashAd.SplashAdListener() {
|
|
|
+ public void onAdSkip() { //用户跳过广告回调 Log.i(TAG, "onAdSkip");
|
|
|
+ G.showToast("游可盈-跳过广告");
|
|
|
+ FileUtil.addContentToFile(eventLogFileName, "YKY splash onSkip:" + "\n");
|
|
|
}
|
|
|
- handleEvent(i);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- private void handleSuccess(int i, boolean shouldShow) {
|
|
|
- if (i == KLSplashAdEvent_CreativeDownloadSuccess) {
|
|
|
- if (shouldShow) showAd();
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- private void handleEvent(int i) {
|
|
|
- switch (i) {
|
|
|
- case KLSplashAdEvent_MeetTheRewardConditions:
|
|
|
- //满足领奖条件,去领奖
|
|
|
- G.showToast("游可盈video 触发奖励(未真正获取)");
|
|
|
- break;
|
|
|
- case KLSplashAdEvent_AdPlayCompletion:
|
|
|
- //一个视频播放结束
|
|
|
- G.showToast("游可盈video 播放结束");
|
|
|
- break;
|
|
|
- case KLSplashAdEvent_AdSkip:
|
|
|
- //用户点击关闭了界面
|
|
|
- G.showToast("游可盈video 关闭");
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //展示优投开屏广告(新增boolean state:false----定值) 重要 mForceGoMain跳转主页 请参照此方法调用,否则可能导致广告展示链路断开 导致收益下降!!!
|
|
|
- private void launchYTSplash() {
|
|
|
- if (flSplashYT != null)
|
|
|
- flSplashYT.setVisibility(View.VISIBLE);
|
|
|
- new SplashEngine(DataGoAct.this, false, new SplashEngine.SplashAdCallBack() {
|
|
|
- @Override
|
|
|
- public void onSplashClick() {
|
|
|
- G.showToast("优投-点击广告");
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onSplashDismissed() {
|
|
|
- G.showToast("优投-广告消失");
|
|
|
- if (flSplashYT != null)
|
|
|
- flSplashYT.setVisibility(View.INVISIBLE);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onSplashError(String err, boolean isTimeout) {
|
|
|
- G.showToast("优投-开屏广告" + err);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onSplashShow() {
|
|
|
- yt_splash_skip_view.setVisibility(View.VISIBLE);
|
|
|
- G.showToast("优投-广告展示成功");
|
|
|
- //mHasLoaded = true;
|
|
|
- //mHandler.removeCallbacksAndMessages(null);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onSplashPresent() {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onSplashLoad() {
|
|
|
- G.showToast("优投-广告加载");
|
|
|
- }
|
|
|
-
|
|
|
- }).launchSplash(flSplashYT, 5 * 1000);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- //掌酷广告控制器
|
|
|
- private AtomicReference<ISplashAdController> splashControllerRef = new AtomicReference<>();
|
|
|
-
|
|
|
- //展示掌酷广告
|
|
|
- private void launchZKSplash() {
|
|
|
- LySdk.loadSplashAd(this, new LySplashAdBuilder(zk_root, "52916"), new ISplashAdLoadCallback() {
|
|
|
- @Override
|
|
|
- public void onFailed(int i, String s) {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onLoaded(ISplashAdController iSplashAdController) {
|
|
|
- splashControllerRef.set(iSplashAdController);
|
|
|
- ISplashAdController controller;
|
|
|
- if ((controller = splashControllerRef.getAndSet(null)) != null) {
|
|
|
- if (zk_root != null)
|
|
|
- zk_root.setVisibility(View.VISIBLE);
|
|
|
- controller.show(new ISplashAdCallback() {
|
|
|
- @Override
|
|
|
- public void onLoadFail(int i, String s) {
|
|
|
- zk_root.setVisibility(View.INVISIBLE);
|
|
|
- G.showToast("掌酷-开屏广告加载onFail" + i + " " + s);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onAdClick() {
|
|
|
- zk_root.setVisibility(View.INVISIBLE);
|
|
|
- G.showToast("掌酷-开屏广告点击");
|
|
|
+ public void onAdShow() { //广告曝光回调
|
|
|
+ G.showToast("游可盈-广告展示成功");
|
|
|
+ splashSuccessCount++;
|
|
|
+ FileUtil.addContentToFile(successCountLogFileName, "YKY splash success count: " + splashSuccessCount + "\n");
|
|
|
+ FileUtil.addContentToFile(eventLogFileName, "YKY splash onSuccess" + "\n");
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void onAdShow() {
|
|
|
- G.showToast("掌酷-开屏广告展示成功");
|
|
|
+ public void onAdClick() { //广告点击回调 Log.i(TAG, "onAdClick");
|
|
|
+ G.showToast("游可盈-点击广告");
|
|
|
+ FileUtil.addContentToFile(eventLogFileName, "YKY splash onAdClick:" + "\n");
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void onAdSkip() {
|
|
|
- zk_root.setVisibility(View.INVISIBLE);
|
|
|
- G.showToast("掌酷-开屏广告跳过");
|
|
|
+ public void onAdClosed() { //广告关闭回调
|
|
|
+ Log.i(TAG, "onAdClosed");
|
|
|
+ G.showToast("游可盈-关闭广告");
|
|
|
+ FileUtil.addContentToFile(eventLogFileName, "YKY splash onAdClose:" + "\n");
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void onAdTimeOver() {
|
|
|
- //zk_root.setVisibility(View.INVISIBLE);
|
|
|
- G.showToast("掌酷-开屏广告倒计时完成");
|
|
|
+ public void onAdError(int i, String err) { //广告展示失败回调
|
|
|
+ Log.e(TAG, "onAdError err: " + i + " " + err);
|
|
|
+ FileUtil.addContentToFile(eventLogFileName, "YKY splash onAdError:" + i + "\n");
|
|
|
+ //拉取广告错误或超时,直接跳过
|
|
|
+ G.showToast("游可盈-onFail" + i);
|
|
|
}
|
|
|
});
|
|
|
- } else {
|
|
|
- Toast.makeText(DataGoAct.this, "掌酷广告未加载", Toast.LENGTH_SHORT).show();
|
|
|
+ mSplashAd.show(); //展示开屏广告 }
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- private AtomicReference<IRewardVideoController> videoControllerRef = new AtomicReference<>();
|
|
|
+ //展示游可盈video
|
|
|
+ private void showYKYCourage() {
|
|
|
+ preAndShowYKYCourageAd();
|
|
|
+ }
|
|
|
|
|
|
- //展示掌酷video
|
|
|
- private void showZKCourage() {
|
|
|
- int adId = 52917;
|
|
|
+ //预加载游可盈video
|
|
|
+ RewardAd mRewardAd;
|
|
|
|
|
|
- LySdk.loadRewardVideo(DataGoAct.this, String.valueOf(adId), new IRewardVideoLoadCallback() {
|
|
|
- @Override
|
|
|
- public void onFailed(int i, String s) {
|
|
|
- G.showToast("掌酷video onFailed" + i + " " + s);
|
|
|
+ private void preAndShowYKYCourageAd() {
|
|
|
+
|
|
|
+ videoTotalCount++;
|
|
|
+ FileUtil.addContentToFile(successCountLogFileName, "YKY video total count:" + videoTotalCount + "\n");
|
|
|
+
|
|
|
+ int posId = 30113; //正式30113 测试30031
|
|
|
+ RewardAdRequest.Builder rewardAdBuilder = new RewardAdRequest.Builder();
|
|
|
+ rewardAdBuilder.autoMute(true)//【可选】设置是否自动静音,默认 false
|
|
|
+ .setRewardTrigger(RewardAdRequest.TRIGGER_OTHER)//【可选】激励类型
|
|
|
+ .setPosId(posId)//【必须】激励视频广告位 id
|
|
|
+ .setAdCount(1);//【可选】广告个数,默认 1
|
|
|
+
|
|
|
+ RewardAd.load(rewardAdBuilder.build(), new RewardAd.RewardAdLoadListener() {//激励视频广告加载回 调
|
|
|
+ public void onAdLoadError(int i, String msg) {
|
|
|
+ FileUtil.addContentToFile(eventLogFileName, "YKY video onFail:" + i + "\n");
|
|
|
+ G.showToast("游可盈video 加载onFail" + i);
|
|
|
+ // 加载失败,err 是错误码,msg 是描述信息 Log.e(TAG, "reward ad load err: " + err + " " + msg);
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void onLoaded(IRewardVideoController iRewardVideoController) {
|
|
|
- videoControllerRef.set(iRewardVideoController);
|
|
|
- IRewardVideoController controller;
|
|
|
- if ((controller = videoControllerRef.getAndSet(null)) != null) {
|
|
|
- controller.show(new IRewardVideoPlayCallback() {
|
|
|
+ public void onAdLoaded(RewardAd ad) {
|
|
|
+ // 广告素材下载完成,参数 ad 为激励视频广告实例
|
|
|
+ // 在此回调中触发展示广告,则使用本地播放的方式读取广告 Log.i(TAG, "reward ad loaded");
|
|
|
+ mRewardAd = ad;
|
|
|
+ if (mRewardAd != null) {
|
|
|
+ //设置激励视频广告展示回调
|
|
|
+ mRewardAd.setListener(new RewardAd.RewardAdListener() {
|
|
|
@Override
|
|
|
- public void onAdShow() {
|
|
|
- G.showToast("掌酷video 展示成功");
|
|
|
+ public void onAdSkip() { //用户跳过广告回调 Log.i(TAG, "onAdSkip");
|
|
|
+ FileUtil.addContentToFile(eventLogFileName, "YKY video onSkip" + "\n");
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void onInterTriggered() {
|
|
|
- G.showToast("掌酷video 点击");
|
|
|
+ public void onReward() { //激励发放回调
|
|
|
+ Log.i(TAG, "onReward");
|
|
|
+ FileUtil.addContentToFile(eventLogFileName, "YKY video onReward:" + "\n");
|
|
|
+ G.showToast("游可盈video 触发奖励(未真正获取)");
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void onAdClose() {
|
|
|
- G.showToast("掌酷video 关闭");
|
|
|
+ public void onVideoComplete() { //视频播放完成回调
|
|
|
+ Log.i(TAG, "onVideoComplete");
|
|
|
+ FileUtil.addContentToFile(eventLogFileName, "YKY video onVideoComplete" + "\n");
|
|
|
+ G.showToast("游可盈video 播放结束");
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void onVideoComplete() {
|
|
|
- G.showToast("掌酷video 播放完成");
|
|
|
+ public void onAdShow() { //广告曝光回调 Log.i(TAG, "onAdShow");
|
|
|
+ videoSuccessCount++;
|
|
|
+ FileUtil.addContentToFile(eventLogFileName, "YKY video onVideoSuccess" + "\n");
|
|
|
+ FileUtil.addContentToFile(successCountLogFileName, "YKY video success count:" + videoSuccessCount + "\n");
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void onRewarded() {
|
|
|
- G.showToast("掌酷video 触发奖励(未真正获取)");
|
|
|
+ public void onAdClick() { //广告点击回调
|
|
|
+ Log.i(TAG, "onAdClick");
|
|
|
+ FileUtil.addContentToFile(eventLogFileName, "YKY video onVideoClick:" + "\n");
|
|
|
+ }
|
|
|
+
|
|
|
+ public void onAdClosed() { //广告关闭回调 Log.i(TAG, "onAdClosed");
|
|
|
+ G.showToast("游可盈video 关闭");
|
|
|
+ FileUtil.addContentToFile(eventLogFileName, "YKY video onVideoClose" + "\n");
|
|
|
+ }
|
|
|
+
|
|
|
+ public void onAdError(int i, String msg) {
|
|
|
+ //广告展示失败回调
|
|
|
+ Log.e(TAG, "onAdError err: " + i + " " + msg);
|
|
|
+ FileUtil.addContentToFile(eventLogFileName, "YKY video onError:" + i + " " + msg + "\n");
|
|
|
}
|
|
|
});
|
|
|
- } else {
|
|
|
- Toast.makeText(DataGoAct.this, "广告未加载成功", Toast.LENGTH_SHORT).show();
|
|
|
+ mRewardAd.show(); //展示激励视频广告
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ //请求权限
|
|
|
+ public boolean requestPermissions() {
|
|
|
+ List<String> permissions = new ArrayList<>();
|
|
|
+ boolean result = true;
|
|
|
+ if (ContextCompat.checkSelfPermission(
|
|
|
+ this,
|
|
|
+ Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
|
|
+ permissions.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
|
|
+ permissions.add(Manifest.permission.READ_EXTERNAL_STORAGE);
|
|
|
+ result = false;
|
|
|
+ }
|
|
|
+ if (permissions.size() > 0) {
|
|
|
+ String[] permissionArrays = new String[permissions.size()];
|
|
|
+ permissionArrays = permissions.toArray(permissionArrays);
|
|
|
+ ActivityCompat.requestPermissions(this, permissionArrays, 1111);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
}
|