广告奖励

This commit is contained in:
18631081161 2025-01-11 17:50:58 +08:00
parent 2333d793f2
commit 64bd220cde
6 changed files with 64 additions and 23 deletions

View File

@ -155,13 +155,8 @@ public class MainActivity extends FlutterActivity {
//加载广告
private void loadAd() {
TTAdNative adNativeLoader = TTAdSdk.getAdManager().createAdNative(MainActivity.this);
AdSlot adslot = new AdSlot.Builder()
.setCodeId("962545848")
.setOrientation(TTAdConstant.VERTICAL)//横竖屏设置
.setMediationAdSlot(new MediationAdSlot
.Builder()
.build())
.build();
AdSlot adslot = new AdSlot.Builder().setCodeId("962545848").setOrientation(TTAdConstant.VERTICAL)//横竖屏设置
.setMediationAdSlot(new MediationAdSlot.Builder().build()).build();
//广告加载监听
adNativeLoader.loadRewardVideoAd(adslot, new TTAdNative.RewardVideoAdListener() {
@Override
@ -197,27 +192,27 @@ public class MainActivity extends FlutterActivity {
mTTRewardVideoAd.setRewardAdInteractionListener(new TTRewardVideoAd.RewardAdInteractionListener() {
@Override
public void onAdShow() {
Log.d("TAG", "onAdShow: ");
Log.d("TAG", "playAd--onAdShow: ");
}
@Override
public void onAdVideoBarClick() {
Log.d(TAG, "onAdVideoBarClick: ");
Log.d(TAG, "playAd--onAdVideoBarClick: ");
}
@Override
public void onAdClose() {
Log.d(TAG, "onAdClose: ");
Log.d(TAG, "playAd--onAdClose: ");
}
@Override
public void onVideoComplete() {
Log.d(TAG, "onVideoComplete: ");
Log.d(TAG, "playAd--onVideoComplete: ");
}
@Override
public void onVideoError() {
Log.d(TAG, "onVideoError: ");
Log.d(TAG, "playAd--onVideoError: ");
}
@Override //已废弃请使用onRewardArrived方法
@ -227,15 +222,21 @@ public class MainActivity extends FlutterActivity {
@Override
public void onRewardArrived(boolean isRewardValid, int rewardType, Bundle extraInfo) {//奖励是否发放请依据isRewardValid
Log.d("TAG", "onRewardArrived: isRewardValid==" + isRewardValid);
Log.d("TAG", "onRewardArrived: rewardType==" + rewardType);
Log.d("TAG", "onRewardArrived: extraInfo==" + extraInfo);
Log.d("TAG", "playAd--onRewardArrived: isRewardValid==" + isRewardValid);
Log.d("TAG", "playAd--onRewardArrived: rewardType==" + rewardType);
Log.d("TAG", "playAd--onRewardArrived: extraInfo==" + extraInfo);
if (isRewardValid) {
Map<String, String> map = new HashMap<>();
map.put("AdSuccess", "AdSuccess");
nativeChannel.invokeMethod("AdSuccess", map);
}
}
@Override
public void onSkippedVideo() {
Log.d(TAG, "onSkippedVideo: ");
Log.d(TAG, "playAd--onSkippedVideo: ");
}
});
@ -253,8 +254,7 @@ public class MainActivity extends FlutterActivity {
case SDK_PAY_FLAG:
//这里接收支付宝的回调信息
//需要注意的是支付结果一定要调用自己的服务端来确定不能通过支付宝的回调结果来判断
@SuppressWarnings("unchecked")
PayResult payResult = new PayResult((Map<String, String>) msg.obj);
@SuppressWarnings("unchecked") PayResult payResult = new PayResult((Map<String, String>) msg.obj);
/**
* 对于支付结果请商户依赖服务端的异步通知结果同步通知结果仅作为支付结束的通知
*/

View File

@ -40,3 +40,8 @@ class RefreshUserdata extends Event {
class PaySuccess extends Event {
PaySuccess();
}
//广
class AdSuccess extends Event {
AdSuccess();
}

View File

@ -4,7 +4,6 @@ import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:talk/network/NetworkConfig.dart';
import 'package:talk/tools/creat/create_page.dart';
import 'package:talk/tools/home_page.dart';
import 'package:talk/tools/login/login_page.dart';
@ -53,7 +52,6 @@ class _ChatAppState extends State<ChatApp> {
// invokeMethod唤起
Future<dynamic> nativeCallHandler(MethodCall methodCall) async {
switch (methodCall.method) {
case "AlipaySuccess": //
// EasyLoading.showToast("支付成功");
EventBusUtil.fire(PaySuccess());
@ -67,6 +65,10 @@ class _ChatAppState extends State<ChatApp> {
case "payError": //
EasyLoading.showToast("支付失败");
break;
case "AdSuccess": //广
EventBusUtil.fire(AdSuccess());
break;
}
}

View File

@ -77,4 +77,6 @@ class NetworkConfig {
static const String getMemoryCardInfo = "api/Chat/GetMemoryCardInfo"; //
static const String useMemoryCard = "api/Chat/UseMemoryCard"; //使
static const String reward = "api/ad/reward"; //广
}

View File

@ -63,7 +63,6 @@ class MeModel {
Future<void> logout() async {
RequestCenter.instance.request(NetworkConfig.logout, {}, (BaseEntity dataEntity) {
if (dataEntity.code == 0) {
streamController.sink.add({
'code': "logout", //
'data': dataEntity.data,
@ -78,4 +77,23 @@ class MeModel {
print("errorEntity==${errorEntity.message}");
});
}
///广
Future<void> reward() async {
RequestCenter.instance.request(NetworkConfig.reward, {}, (BaseEntity dataEntity) {
if (dataEntity.code == 0) {
streamController.sink.add({
'code': "reward", //
'data': dataEntity.message,
});
} else {
streamController.sink.add({
'code': "error", //
'data': dataEntity.message,
});
}
}, (ErrorEntity errorEntity) {
print("errorEntity==${errorEntity.message}");
});
}
}

View File

@ -3,6 +3,7 @@ import 'dart:async';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:talk/tools/me/me_model.dart';
import '../../beans/me_character_info_bean.dart';
@ -26,6 +27,8 @@ class _MePageState extends State<MePage> {
late UserInfoBean userInfoBean;
StreamSubscription<RefreshUserdata>? _refreshUserdata;
StreamSubscription<AdSuccess>? _adSuccess;
@override
void initState() {
// TODO: implement initState
@ -35,6 +38,11 @@ class _MePageState extends State<MePage> {
_loadData();
});
//广
_adSuccess = EventBusUtil.listen((event) {
_viewmodel.reward();
});
subscription = _viewmodel.streamController.stream.listen((newData) {
String code = newData['code'];
if (code.isNotEmpty) {
@ -42,6 +50,11 @@ class _MePageState extends State<MePage> {
case "getUserInfo":
userInfoBean = newData['data'];
break;
case "reward":
EasyLoading.showToast(newData['data']);
_loadData();
break;
}
setState(() {});
}
@ -56,9 +69,10 @@ class _MePageState extends State<MePage> {
@override
void dispose() {
// TODO: implement dispose
_refreshUserdata?.cancel();
subscription.cancel();
super.dispose();
_refreshUserdata?.cancel();
_adSuccess?.cancel();
subscription.cancel();
}
goChatPage(String id) {