Skip to content

Commit

Permalink
完善android 激励广告、开屏广告、banner广告、动态信息流/横幅/视频贴片广告
Browse files Browse the repository at this point in the history
  • Loading branch information
gstory0404 committed Aug 10, 2021
1 parent 58390fd commit 3876e94
Show file tree
Hide file tree
Showing 33 changed files with 1,732 additions and 149 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
**/android/gradlew.bat
**/android/local.properties
**/android/**/GeneratedPluginRegistrant.java
**/android/key/

# iOS/XCode related
**/ios/**/*.mode1v3
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.0.1

* TODO: Describe initial release.

## 0.0.2

* TODO: 1、完善android 激励广告、开屏广告、banner广告、动态信息流/横幅/视频贴片广告
249 changes: 247 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,248 @@
# flutter_tencentad
# 腾讯优量汇广告 Flutter版本

https://developers.adnet.qq.com/doc/android/union/union_embed
<p>
<a href="https://pub.flutter-io.cn/packages/flutter_tencentad"><img src=https://img.shields.io/badge/flutter_tencentad-v0.0.2-success></a>
</p>

## 简介
flutter_tencentad是一款集成了腾讯优量汇广告Android和iOSSDK的Flutter插件,方便直接调用优量汇广告SDK方法快速开发

## 官方文档
* [Android](https://developers.adnet.qq.com/doc/android/access_doc)
* [IOS](https://developers.adnet.qq.com/doc/ios/guide)

## 本地环境
```
[✓] Flutter (Channel stable, 2.2.3, on macOS 11.5.1 20G80 darwin-x64, locale zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 2020.3)
[✓] VS Code (version 1.56.2)
[✓] Connected device (2 available)
```

## 集成步骤
#### 1、pubspec.yaml
```Dart
flutter_tencentad: ^0.0.2
```
引入
```Dart
import 'package:flutter_tencentad/flutter_tencentad.dart';
```
#### 2、Android
SDK(4.380.1250)已配置插件中无需额外配置,只需要在android目录中AndroidManifest.xml配置
```Java
<manifest ···
xmlns:tools="http://schemas.android.com/tools"
···>
<application
tools:replace="android:label">
```

#### 3、IOS

开发中

## 使用

#### 1、SDK初始化
```Dart
await FlutterTencentad.register(
appId: "1200009850", //appid
debug: true, //是否显示日志log
);
```
#### 2、获取SDK版本
```Dart
await FlutterTencentad.getSDKVersion();
```

#### 3、开屏广告
```Dart
FlutterTencentad.splashAdView(
//广告id
codeId: "4052216802299999",
////设置开屏广告从请求到展示所花的最大时长(并不是指广告曝光时长),取值范围为[1500, 5000]ms
fetchDelay: 3000,
//广告回调
callBack: SplashAdCallBack(
onShow: () {
print("开屏广告显示");
},
onADTick: (time) {
print("开屏广告倒计时剩余时间 $time");
},
onClick: () {
print("开屏广告点击");
},
onClose: () {
print("开屏广告关闭");
Navigator.pop(context);
},
onExpose: () {
print("开屏广告曝光");
},
onFail: (code, message) {
print("开屏广告失败 $code $message");
},
),
),
```
#### 4、banner广告
```Dart
FlutterTencentad.bannerAdView(
//广告id
codeId: "8042711873318113",
//广告宽 单位dp
viewWidth: 500,
//广告高 单位dp 宽高比应该为6.4:1
viewHeight: 100,
// 广告回调
callBack: BannerAdCallBack(
onShow: () {
print("Banner广告显示");
},
onFail: (code, message) {
print("Banner广告错误 $code $message");
},
onClose: () {
print("Banner广告关闭");
},
onExpose: () {
print("Banner广告曝光");
},
onClick: () {
print("Banner广告点击");
},
),
),
```

#### 5、动态信息流/横幅/视频贴片广告
```
FlutterTencentad.expressAdView(
//广告id
codeId: "4072918853903023",
//广告宽 单位dp
viewWidth: 400,
//广告高 单位dp
viewHeight: 300,
//回调事件
callBack: ExpressAdCallBack(
onShow: () {
print("动态信息流广告显示");
},
onFail: (code, message) {
print("动态信息流广告错误 $code $message");
},
onClose: () {
print("动态信息流广告关闭");
},
onExpose: () {
print("动态信息流广告曝光");
},
onClick: () {
print("动态信息流广告点击");
},
)
),
```

#### 6、激励视频广告
预加载激励视频广告
```Dart
await FlutterTencentad.loadRewardVideoAd(
//广告id
codeId: "5042816813706194",
);
```
显示激励视频广告
```dart
await FlutterTencentad.showRewardVideoAd();
```
监听激励视频结果

```Dart
FlutterTencentAdStream.initAdStream(
//激励广告
rewardAdCallBack: RewardAdCallBack(
onShow: () {
print("激励广告显示");
},
onClick: () {
print("激励广告点击");
},
onFail: (code, message) {
print("激励广告失败 $code $message");
},
onClose: () {
print("激励广告关闭");
},
onReady: () async {
print("激励广告预加载准备就绪");
await FlutterTencentad.showRewardVideoAd();
},
onUnReady: () {
print("激励广告预加载未准备就绪");
},
onVerify: (transId) {
print("激励广告奖励 $transId");
},
),
);
```
#### 7、插屏广告
预加载插屏广告
```dart
await FlutterTencentad.loadUnifiedInterstitialAD(
//广告id
codeId: "9062813863614416",
//是否全屏
isFullScreen: false,
);
```

显示插屏广告
```dart
await FlutterTencentad.showUnifiedInterstitialAD();
```

插屏广告结果监听
```dart
FlutterTencentAdStream.initAdStream(
interactionAdCallBack: InteractionAdCallBack(
onShow: () {
print("插屏广告显示");
},
onClick: () {
print("插屏广告点击");
},
onFail: (code, message) {
print("插屏广告失败 $code $message");
},
onClose: () {
print("插屏广告关闭");
},
onReady: () async {
print("插屏广告预加载准备就绪");
await FlutterTencentad.showUnifiedInterstitialAD();
},
onUnReady: () {
print("插屏广告预加载未准备就绪");
},
),
);
```

## 版本更新

[更新日志](https://github.com/gstory0404/flutter_tencentad/blob/master/CHANGELOG.md)


## 联系方式
* Email: gstory0404@gmail.com

* QQ群: <a target="_blank" href="https://qm.qq.com/cgi-bin/qm/qr?k=4j2_yF1-pMl58y16zvLCFFT2HEmLf6vQ&jump_from=webapi"><img border="0" src="//pub.idqqimg.com/wpa/images/group.png" alt="649574038" title="flutter交流"></a>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ package com.gstory.flutter_tencentad
class FlutterTencentAdConfig {

companion object {
//event事件
const val adevent = "com.gstory.flutter_tencentad/adevent"
//BannerAdView
const val bannerAdView = "com.gstory.flutter_tencentad/BannerAdView"
//SplashAdView
const val splashAdView = "com.gstory.flutter_tencentad/SplashAdView"
//NativeExpressADView
const val nativeExpressAdView = "com.gstory.flutter_tencentad/NativeExpressAdView"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.gstory.flutter_unionad

import android.content.Context
import com.gstory.flutter_tencentad.FlutterTencentAdConfig
import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.plugin.common.EventChannel

/**
* @Description:
* @Author: gstory0404@gmail
* @CreateDate: 2020/8/19 18:52
*/
class FlutterTencentAdEventPlugin : FlutterPlugin, EventChannel.StreamHandler {

companion object {
private var eventChannel: EventChannel? = null

private var eventSink: EventChannel.EventSink? = null

private var context: Context? = null

fun sendContent(content: MutableMap<String, Any?>) {
eventSink?.success(content);
}
}

override fun onListen(arguments: Any?, events: EventChannel.EventSink?) {
eventSink = events
}

override fun onCancel(arguments: Any?) {
eventSink = null
}

override fun onAttachedToEngine(binding: FlutterPlugin.FlutterPluginBinding) {
eventChannel = EventChannel(binding.binaryMessenger, FlutterTencentAdConfig.adevent)
eventChannel!!.setStreamHandler(this)
context = binding.applicationContext
}

override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) {
eventChannel = null
eventChannel!!.setStreamHandler(null)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.content.Context
import androidx.annotation.NonNull
import com.gstory.flutter_tencentad.interstitialad.InterstitialAd
import com.gstory.flutter_tencentad.rewardvideoad.RewardVideoAd
import com.gstory.flutter_unionad.FlutterTencentAdEventPlugin
import com.qq.e.comm.managers.GDTADManager
import com.qq.e.comm.managers.status.SDKStatus
import io.flutter.embedding.engine.plugins.FlutterPlugin
Expand Down Expand Up @@ -49,6 +50,7 @@ class FlutterTencentadPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
channel.setMethodCallHandler(this)
applicationContext = flutterPluginBinding.applicationContext
mFlutterPluginBinding = flutterPluginBinding
FlutterTencentAdEventPlugin().onAttachedToEngine(flutterPluginBinding)
}

override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.gstory.flutter_tencentad

import android.app.Activity
import com.gstory.flutter_tencentad.bannerad.BannerAdViewFactory
import com.gstory.flutter_tencentad.expressad.NativeExpressAdViewFactory
import com.gstory.flutter_tencentad.splashad.SplashAdViewFactory
import io.flutter.embedding.engine.plugins.FlutterPlugin

/**
Expand All @@ -11,8 +13,12 @@ import io.flutter.embedding.engine.plugins.FlutterPlugin
*/

object FlutterTencentAdViewPlugin {
fun registerWith(binding: FlutterPlugin.FlutterPluginBinding, activity : Activity) {
fun registerWith(binding: FlutterPlugin.FlutterPluginBinding, activity: Activity) {
//注册banner广告
binding.platformViewRegistry.registerViewFactory(FlutterTencentAdConfig.bannerAdView, BannerAdViewFactory(binding.binaryMessenger,activity))
binding.platformViewRegistry.registerViewFactory(FlutterTencentAdConfig.bannerAdView, BannerAdViewFactory(binding.binaryMessenger, activity))
//注册splash广告
binding.platformViewRegistry.registerViewFactory(FlutterTencentAdConfig.splashAdView, SplashAdViewFactory(binding.binaryMessenger,activity))
//注册Express广告
binding.platformViewRegistry.registerViewFactory(FlutterTencentAdConfig.nativeExpressAdView, NativeExpressAdViewFactory(binding.binaryMessenger,activity))
}
}
Loading

0 comments on commit 3876e94

Please sign in to comment.