flutter_tencentad是一款集成了腾讯优量汇广告(广点通)Android和iOS SDK的Flutter插件,方便直接调用优量汇(广点通)广告SDK方法快速开发,体验demo,可通过GTAds实现多个广告平台接入、统一管理。
[✓] Flutter (Channel stable, 3.16.6, on macOS 14.2.1 23C71 darwin-x64, locale zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
[✓] Xcode - develop for iOS and macOS (Xcode 15.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.1)
[✓] Android Studio (version 2023.1)
[✓] IntelliJ IDEA Ultimate Edition (version 2023.3.2)
[✓] VS Code (version 1.85.2)
[✓] Connected device (4 available)
[✓] Network resources
flutter_tencentad: ^latest
引入
import 'package:flutter_tencentad/flutter_tencentad.dart';
bidding模式下 必需要调用对应Controller 回传竞价结果
需要在android目录中AndroidManifest.xml配置
<manifest ···
xmlns:tools="http://schemas.android.com/tools"
···>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
tools:replace="android:label">
根据SDK文档配置。因为使用PlatformView,在Info.plist加入
<key>io.flutter.embedded_views_preview</key>
<true/>
await FlutterTencentad.register(
androidId: "1200009850",//androidId
iosId: "1200082163", //iosId
debug: true, //是否显示日志log
personalized: FlutterTencentadPersonalized.show,//是否显示个性化推荐广告
channelId: FlutterTencentadChannel.other,//渠道id
);
await FlutterTencentad.getSDKVersion();
FlutterTencentAdBiddingController _bidding =
new FlutterTencentAdBiddingController();
FlutterTencentad.splashAdView(
//android广告id
androidId: widget.androidId,
//ios广告id
iosId: widget.iosId,
////设置开屏广告从请求到展示所花的最大时长(并不是指广告曝光时长),取值范围为[1500, 5000]ms
fetchDelay: 3000,
//下载二次确认弹窗 默认false
downloadConfirm: true,
//是否开启竞价 默认不开启
isBidding: widget.isBidding,
//竞价结果回传
bidding: _bidding,
//广告回调
callBack: FlutterTencentadSplashCallBack(onShow: () {
print("开屏广告显示");
}, onADTick: (time) {
print("开屏广告倒计时剩余时间 $time");
}, onClick: () {
print("开屏广告点击");
}, onClose: () {
print("开屏广告关闭");
Navigator.pop(context);
}, onExpose: () {
print("开屏广告曝光");
}, onFail: (code, message) {
print("开屏广告失败 $code $message");
Navigator.pop(context);
}, onECPM: (ecpmLevel, ecpm) {
print("开屏广告竞价 ecpmLevel=$ecpmLevel ecpm=$ecpm");
//规则 自己根据业务处理
if (ecpm > 0) {
//竞胜出价,类型为Integer
//最大竞败方出价,类型为Integer
_bidding.biddingResult(
FlutterTencentBiddingResult().success(ecpm, 0));
} else {
//竞胜方出价(单位:分),类型为Integer
//优量汇广告竞败原因 FlutterTencentAdBiddingLossReason
//竞胜方渠道ID FlutterTencentAdADNID
_bidding.biddingResult(FlutterTencentBiddingResult().fail(
1000,
FlutterTencentAdBiddingLossReason.LOW_PRICE,
FlutterTencentAdADNID.othoerADN));
}
}),
),
FlutterTencentAdBiddingController _bidding =
new FlutterTencentAdBiddingController();
FlutterTencentad.bannerAdView(
//android广告id
androidId: "8042711873318113",
//ios广告id
iosId: "6062430096832369",
//广告宽 单位dp
viewWidth: 500,
//广告高 单位dp 宽高比应该为6.4:1
viewHeight: 100,
//下载二次确认弹窗 默认false
downloadConfirm: true,
//是否开启竞价 默认不开启
isBidding: widget.isBidding,
//竞价结果回传
bidding: _bidding,
// 广告回调
callBack: FlutterTencentadBannerCallBack(
onShow: () {
print("Banner广告显示");
},
onFail: (code, message) {
print("Banner广告错误 $code $message");
},
onClose: () {
print("Banner广告关闭");
},
onExpose: () {
print("Banner广告曝光");
},
onClick: () {
print("Banner广告点击");
}, onECPM: (ecpmLevel, ecpm) {
print("Banner广告竞价 ecpmLevel=$ecpmLevel ecpm=$ecpm");
//规则 自己根据业务处理
if (ecpm > 0) {
//竞胜出价,类型为Integer
//最大竞败方出价,类型为Integer
_bidding.biddingResult(
FlutterTencentBiddingResult().success(ecpm, 0));
} else {
//竞胜方出价(单位:分),类型为Integer
//优量汇广告竞败原因 FlutterTencentAdBiddingLossReason
//竞胜方渠道ID FlutterTencentAdADNID
_bidding.biddingResult(FlutterTencentBiddingResult().fail(
1000,
FlutterTencentAdBiddingLossReason.LOW_PRICE,
FlutterTencentAdADNID.othoerADN));
}
},
),
),
FlutterTencentAdBiddingController _bidding =
new FlutterTencentAdBiddingController();
FlutterTencentad.expressAdView(
//android广告id
androidId: "4033498034524284",
//ios广告id
iosId: "4033278955532222",
viewWidth: 400,
viewHeight: 300,
//下载二次确认弹窗 默认false
downloadConfirm: true,
//是否开启竞价模式
isBidding: true,
bidding: _bidding,
//回调事件
callBack: FlutterTencentadExpressCallBack(
onShow: () {
print("动态信息流广告显示");
},
onFail: (code, message) {
print("动态信息流广告错误 $code $message");
},
onClose: () {
print("动态信息流广告关闭");
},
onExpose: () {
print("动态信息流广告曝光");
},
onClick: () {
print("动态信息流广告点击");
},
onECPM: (ecpmLevel, ecpm) {
print("动态信息流广告竞价 ecpmLevel=$ecpmLevel ecpm=$ecpm");
//规则 自己根据业务处理
if (ecpm > 0) {
//竞胜出价,类型为Integer
//最大竞败方出价,类型为Integer
_bidding.biddingResult(
FlutterTencentBiddingResult().success(ecpm, 0));
} else {
//竞胜方出价(单位:分),类型为Integer
//优量汇广告竞败原因 FlutterTencentAdBiddingLossReason
//竞胜方渠道ID FlutterTencentAdADNID
_bidding.biddingResult(FlutterTencentBiddingResult().fail(
1000,
FlutterTencentAdBiddingLossReason.LOW_PRICE,
FlutterTencentAdADNID.othoerADN));
}
}
),
),
预加载激励视频广告
await FlutterTencentad.loadRewardVideoAd(
//android广告id
androidId: "5042816813706194",
//ios广告id
iosId: "8062535056034159",
//用户id
userID: "123",
//奖励
rewardName: "100金币",
//奖励数
rewardAmount: 100,
//扩展参数 服务器回调使用
customData: ""
//下载二次确认弹窗 默认false
downloadConfirm: true,
//是否开启竞价
isBidding: true,
);
显示激励视频广告
await FlutterTencentad.showRewardVideoAd();
监听激励视频结果
当为竞价时触发onECPM,否则触发onReady
FlutterTencentAdStream.initAdStream(
//激励广告
flutterTencentadRewardCallBack: FlutterTencentadRewardCallBack(
onShow: () {
print("激励广告显示");
},
onClick: () {
print("激励广告点击");
},
onFail: (code, message) {
print("激励广告失败 $code $message");
},
onClose: () {
print("激励广告关闭");
},
onReady: () async {
print("激励广告预加载准备就绪");
await FlutterTencentad.showRewardVideoAd();
},
onUnReady: () {
print("激励广告预加载未准备就绪");
},
onVerify: (transId,rewardName,rewardAmount) {
print("激励广告奖励 $transId $rewardName $rewardAmount");
},
onFinish: (){
print("激励广告完成");
},
onECPM: (ecpmLevel, ecpm) async {
print("激励广告竞价 ecpmLevel=$ecpmLevel ecpm=$ecpm");
//规则 自己根据业务处理
if (ecpm > 0) {
//竞胜出价,类型为Integer
//最大竞败方出价,类型为Integer
await FlutterTencentad.showRewardVideoAd(
result: FlutterTencentBiddingResult().success(ecpm, 0));
} else {
//竞胜方出价(单位:分),类型为Integer
//优量汇广告竞败原因 FlutterTencentAdBiddingLossReason
//竞胜方渠道ID FlutterTencentAdADNID
await FlutterTencentad.showRewardVideoAd(
result: FlutterTencentBiddingResult().fail(
1000,
FlutterTencentAdBiddingLossReason.LOW_PRICE,
FlutterTencentAdADNID.othoerADN));
}
},
),
);
预加载插屏广告
await FlutterTencentad.loadUnifiedInterstitialAD(
//android广告id
androidId: "9062813863614416",
//ios广告id
iosId: "1052938046031440",
//是否全屏
isFullScreen: false,
//下载二次确认弹窗 默认false
downloadConfirm: true,
//是否开启竞价
isBidding: true,
);
显示插屏广告
await FlutterTencentad.showUnifiedInterstitialAD();
插屏广告结果监听
当为竞价时触发onECPM,否则触发onReady
FlutterTencentAdStream.initAdStream(
flutterTencentadInteractionCallBack: FlutterTencentadInteractionCallBack(
onShow: () {
print("插屏广告显示");
},
onClick: () {
print("插屏广告点击");
},
onFail: (code, message) {
print("插屏广告失败 $code $message");
},
onClose: () {
print("插屏广告关闭");
},
onReady: () async {
print("插屏广告预加载准备就绪");
await FlutterTencentad.showUnifiedInterstitialAD();
},
onUnReady: () {
print("插屏广告预加载未准备就绪");
},
onVerify: (transId,rewardName,rewardAmount){
print("广告奖励凭证id $transId");
},
onECPM: (ecpmLevel, ecpm) async {
print("插屏广告竞价 ecpmLevel=$ecpmLevel ecpm=$ecpm");
//规则 自己根据业务处理
if (ecpm > 0) {
//竞胜出价,类型为Integer
//最大竞败方出价,类型为Integer
await FlutterTencentad.showUnifiedInterstitialAD(
result: FlutterTencentBiddingResult().success(ecpm, 0));
} else {
//竞胜方出价(单位:分),类型为Integer
//优量汇广告竞败原因 FlutterTencentAdBiddingLossReason
//竞胜方渠道ID FlutterTencentAdADNID
await FlutterTencentad.showUnifiedInterstitialAD(
result: FlutterTencentBiddingResult().fail(
1000,
FlutterTencentAdBiddingLossReason.LOW_PRICE,
FlutterTencentAdADNID.othoerADN));
}
},
),
);
await FlutterTencentad.enterAPPDownloadListPage();
插件 | 地址 |
---|---|
字节-穿山甲广告插件 | flutter_unionad |
腾讯-优量汇广告插件 | flutter_tencentad |
百度-百青藤广告插件 | baiduad |
字节-Gromore聚合广告 | gromore |
Sigmob广告 | sigmobad |
聚合广告插件(迁移至GTAds) | flutter_universalad |
GTAds聚合广告 | GTAds |
字节穿山甲内容合作插件 | flutter_pangrowth |
文档预览插件 | file_preview |
滤镜 | gpu_image |
- Email: gstory0404@gmail.com
- Blog:https://www.gstory.cn/