Flutter SDK
一、SDK接入配置
1. 导入SDK
- 将flutter sdk目录中的jucheng_ads_plugin,整个文件夹放入到项目plugins目录下(如果不存在plugins目录,则先新建)。xml目录放在对应的android项目的xml目录下,详见Android配置第4点。
- 编辑 pubspec.yaml 文件
dependencies:
jucheng_ads_plugin:
path: plugins/jucheng_ads_plugin/
执行 flutter pub get 在使用类中引入头文件:
import 'package:jucheng_ads_plugin/jucheng_ads_plugin.dart';
Android配置注意事项
build.gradle
dependencies {
implementation fileTree(include: ['*.jar', '*.aar'], dir: '../../plugins/jucheng_ads_plugin/android/libs')
implementation 'com.squareup.okhttp3:okhttp:3.8.0'
implementation 'com.squareup.okio:okio:1.13.0'
implementation 'com.google.code.gson:gson:2.8.0'
implementation "androidx.appcompat:appcompat:1.2.0"
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.android.support:multidex:1.0.3'
implementation "androidx.recyclerview:recyclerview:1.2.0"
implementation "com.android.support:support-annotations:28.0.0"
// adset广告源依赖
implementation 'io.github.aliyun-sls:aliyun-log-android-sdk:2.7.0'
// 众简广告源依赖
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.7.10"
}
权限声明
<!--联⽹权限-->
<uses-permission android:name="android.permission.INTERNET" />
<!--检测当前⽹络状态是2G、3G、4G还是WiFi-->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!--获取设备标识IMEI。⽤于标识⽤户-->
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<!--读写存储权限-->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
tools:node="replace" />
<!--获取MAC地址,⽤于标识⽤户-->
<uses-permission android:name="android.permission.CHANGE_WIFI_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.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
AndroidManifest.xml Application下增加广告平台的provider
<!--穿山甲-->
<provider android:name="com.bytedance.sdk.openadsdk.TTFileProvider"
android:authorities="${applicationId}.TTFileProvider" android:exported="false"
android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
<!--广点通sdk-->
<provider android:name="com.qq.e.comm.GDTFileProvider"
android:authorities="${applicationId}.gdt.fileprovider" android:exported="false"
android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/gdt_file_path" />
</provider>
sdk解压后xml目录下的文件配置
把sdk目录中的xml文件夹里的文件拷贝到应用android目录的xml文件夹下 如果目录下存在相同的文件,对比下内容,不直接覆盖
android混淆配置
dontwarn com.beizi.fusion.**
-dontwarn com.beizi.ad.**
-keep class com.beizi.fusion.** {*; }
-keep class com.beizi.ad.** {*; }
-ignorewarnings
-dontwarn com.baidu.mobads.sdk.api.**
-keepclassmembers class * extends android.app.Activity{
public void(android.view.View);
}
-keepclassmembers enum *{
public static []values();
public static valueOf(java.lang.String);
}
-keep class com.baidu.mobads.**{*;}
-keep class com.style.widget.**{*;}
-keep class com.component.**{*;}
-keep class com.baidu.ad.magic.flute.**{*;}
-keep class com.baidu.mobstat.forbes.**{*;}
-keep class org.chromium.** {*;}
-keep class org.chromium.** { *; }
-keep class aegon.chrome.** { *; }
-keep class com.kwai.**{ *; }
-keep class com.kwad.**{ *; }
-dontwarn com.kwai.**
-dontwarn com.kwad.**
-dontwarn com.ksad.**
-dontwarn aegon.chrome.**
-keepattributes Signature
-keepattributes Annotation
-dontwarn sun.misc.**
-keep class com.google.gson.examples.android.model.**{<fields>; }
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer
-keep class com.bytedance.sdk.openadsdk.** { *; }
-keep public interface com.bytedance.sdk.openadsdk.downloadnew.** {*;}
-keep class com.pgl.sys.ces.** {*;}
-keep class com.bytedance.embed_dr.** {*;}
-keep class com.bytedance.embedapplog.** {*;}
-dontwarn com.sigmob.**
-keep class com.sigmob.**{ *;}
-keep interface com.sigmob.**{ *;}
-dontwarn com.czhj.**
-keep class com.czhj.**{ *;}
-keep interface com.czhj.**{ *;}
-keep class com.tan.**{ *;}
-dontwarn com.windmill.**
-keep class com.windmill.**.**{*;}
-keep interface com.windmill.**{ *;}
-keep class com.kc.openset.**{*;}
-keep class com.od.**{*;}
-dontwarn com.kc.openset.**
-keep @com.qihoo.SdkProtected.OSETSDK.Keep class **{*;}
-keep,allowobfuscation interface com.qihoo.SdkProtected.OSETSDK.Keep
# 倍业混淆
-dontwarn com.mercury.**
-keep class com.mercury.** {*;}
-keep class com.aliyun.sls.android.producer.** { *; }
-keep interface com.aliyun.sls.android.producer.* { *; }
-keep class com.meishu.sdk.**{*;}
-keep class com.baoyue.adx.** {*;}
-keep class com.baoyue.jucheng_ads_plugin.** {*;}
常见问题
如果编译报了以下错误 Error: Attribute application@allowBackup value=(false)... Suggestion: add 'tools:replace="android:label"' to <application> element at AndroidManifest.xml to override. 这是因为不同上游sdk android:allowBackup、android:label 之前的值设置有冲突。可以在AndroidManifest.xml 做如下设置 在application中增加了android:allowBackup(该值true/false根据自己需求决定) 和 tools:replace属性(需要在xml顶部引入:xmlns:tools="http://schemas.android.com/tools")
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application android:name="${applicationName}"
android:allowBackup="false"
tools:replace="android:allowBackup,android:label"
android:icon="@mipmap/ic_launcher">
其它注意事项
穿山甲是68版本以上,该版本要求minSdkVersion为24,即兼容的最小手机系统版本为7.0,可通过以下两种方式支持: a.修改主项目的最低版本minSdkVersion为24即可解决 b.主项目AndroidManifest.xml调整tools:overrideLibrary标签解决,如果开发者主项目清单已经有tools.overrideLibrary标签,则在已有包名后,增加csj相关库名,并以逗号隔开;如果主项目清单没有该标签,则新增该标签再添加相关库名。示例代码如下:
//聚合开发者需在tools:overrideLibrary标签内添加以下库名:
//com.bytedance.gromore,com.bytedance.sdk.openadsdk,com.bytedance.msdk.adapter.admob,com.bytedance.msdk.adapter.BaiduMobAds,com.bytedance.msdk.adapter.gdt,com.bytedance.msdk.adapter.ks,com.bytedance.msdk.adapter.mintegral,com.bytedance.msdk.adapter.sigmob,com.bytedance.msdk.adapter.unity,com.bytedance.msdk.adapter.xiaomi,com.bytedance.tools
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
...
//如开发者之前无tools:overrideLibrary,则新建
<uses-sdk tools:overrideLibrary=" com.bytedance.gromore,com.bytedance.sdk.openadsdk,com.bytedance.msdk.adapter.admob,com.bytedance.msdk.adapter.BaiduMobAds,com.bytedance.msdk.adapter.gdt,com.bytedance.msdk.adapter.ks,com.bytedance.msdk.adapter.mintegral,com.bytedance.msdk.adapter.sigmob,com.bytedance.msdk.adapter.unity,com.bytedance.msdk.adapter.xiaomi,com.bytedance.tools"/>
//如开发者之前已有tools:overrideLibrary
<uses-sdk tools:overrideLibrary="com.aaa.bbb,com.ccc.ddd" />
//调整后的,新增了 穿山甲相关库,并以逗号隔开
<uses-sdk tools:overrideLibrary="com.aaa.bbb,com.ccc.ddd, com.bytedance.gromore,com.bytedance.sdk.openadsdk,com.bytedance.msdk.adapter.admob,com.bytedance.msdk.adapter.BaiduMobAds,com.bytedance.msdk.adapter.gdt,com.bytedance.msdk.adapter.ks,com.bytedance.msdk.adapter.mintegral,com.bytedance.msdk.adapter.sigmob,com.bytedance.msdk.adapter.unity,com.bytedance.msdk.adapter.xiaomi,com.bytedance.tools"/>
...
</manifest>
iOS配置注意事项
添加“ObjC”链接器标记 在Xcode中选择项目的Targets->Build Settings,配置Other Link Flags 增加 -ObjC。
二、初始化说明
1. 广告初始化
//初始化传入应用id
await JuChengAd.init("appid");
2. iOS动态改包名的方式(非必须)
需要在调用init方法前,调用下修改包名的方法
// 先改包名,传入包名
await JuChengAd.setCusBid("com.test");
// 然后初始化聚合sdk
await JuChengAd.init("appid");
三、开屏广告
1. 主要API
JuChengAdRequest
| 参数 | 说明 |
|---|---|
| pid | 广告位 |
| userId | 媒体用户体系ID ,可选 ,默认null |
| options | 扩展参数,默认null |
JuChengSplashAd
| 方法 | 说明 |
|---|---|
| JuChengSplashAd(required JuChengAdRequest this.request, required this.width, required this.height, this.title, this.desc, required JuChengSplashListener < JuChengSplashAd > this.listener ) | 初始化开屏广告对象, request 为广告请求对象,必传, width广告宽 必传, height 广告位高 必传, title 可选, desc 品牌区应用描述 可选, listener 开屏视频接口 必传 |
| loadAdAndShow() | 加载并展示广告,使用这个方法,加载成功后自动显示广告。不需要分加载和展示两个动作执行 |
| loadAd() | 发起广告加载 |
| isReady() | 判断当前广告是否存在可展示的广告 |
| showAd() | 展示广告 |
| destroy() | 销毁广告 |
JuChengSplashListener 开屏回调说明
| 回调方法 | 说明 |
|---|---|
| onAdSucceed (JuChengSplashAd ad) | 广告加载成功,可在此方法判断isReady后,调用show来展示广告 |
| onAdFailed (JuChengError? error) | 广告加载失败 |
| onAdExposure () | 广告曝光 |
| onAdFailedToPresent (JuChengError? error) | 广告曝光失败 |
| onAdClicked () | 广告被用户点击 |
| onAdClosed () | 广告关闭 |
2. 创建开屏广告对象
JuChengAdRequest request = JuChengAdRequest(pid: pid);
Size size = Size(window.physicalSize.width, window.physicalSize.height);
if(Platform.isIOS){
size = Size(window.physicalSize.width/window.devicePixelRatio, window.physicalSize.height/window.devicePixelRatio);
}
JuChengSplashAd splashAd = JuChengSplashAd( request:request, width:size.width, height:size.heigth,listener: listener);
3. 设置监听回调
class IJuChengSplashListener extends JuChengSplashListener<JuChengSplashAd> {
void onAdClicked() {
print('onAdClicked');
}
void onAdClose() {
print('onAdClose');
}
void onAdExposure() {
print('onAdExposure');
}
void onAdFailed(JuChengError error) {
print('onAdFailed: ${error.message}');
}
void onAdSucceed(JuChengSplashAd ad) async {
print('onAdSucceed');
}
}
4. 开屏广告加载
splashAd.loadAd();
5. 开屏广告播放
bool isReady = await splashAd.isReady();
if(isReady){
splashAd.showAd();
}
四、激励视频广告
1. 主要API
JuChengAdRequest
| 参数 | 说明 |
|---|---|
| pid | 广告位 |
| userId | 媒体用户体系ID ,可选 ,默认null |
| options | 扩展参数,默认null |
JuChengRewardAd
| 方法 | 说明 |
|---|---|
| JuChengRewardAd(required JuChengAdRequest this.request, required JuChengRewardListener < JuChengRewardAd > this.listener) | 初始化激励视频广告对象, request 为广告请求对象,必传, listener 激励视频视频接口 必传 |
| loadAdData() | 发起广告加载 |
| isReady() | 判断当前广告是否存在可展示的广告 |
| showAd() | 展示广告 |
| destroy() | 销毁广告 |
JuChengRewardListener
| 回调方法 | 说明 |
|---|---|
| onAdSucceed (JuChengRewardAd ad) | 广告加载成功,可在此方法判断isReady后,调用show来展示广告 |
| onAdFailed (JuChengError? error) | 广告加载失败 |
| onAdExposure () | 广告曝光 |
| onAdClicked () | 广告被用户点击 |
| onAdClosed () | 广告关闭 |
| onAdReward (JuChengRewardInfo rewardInfo) | 广告获得奖励,参数:广告奖励对象 |
| onVideoComplete () | 广告视频播放结束 |
2. 创建激励广告对象
JuChengAdRequest request = JuChengAdRequest(pid: pid);
JuChengRewardAd juchengRewardAd = JuChengRewardAd( request:request, listener: listener);
3. 设置监听回调
class IJuChengRewardListener extends JuChengRewardListener<JuChengRewardAd> {
void onAdClicked() {
print('onAdClicked');
}
void onAdClose() {
print('onAdClosed');
}
void onAdExposure() {
print('onAdExposure');
}
void onAdFailed(JuChengError error) {
print('onAdFailed: ${error.message}');
}
void onAdReward(JuChengRewardInfo rewardInfo) {
print('JuChengRewardInfo:$rewardInfo');
}
void onAdSucceed(JuChengRewardAd ad) {
print('onAdSucceed');
}
void onVideoComplete() {
print('onVideoComplete');
}
}
4. 激励视频广告加载
juchengRewardAd.loadAdData();
5. 激励视频广告播放
bool isReady = await juchengRewardAd.isReady();
if(isReady){
juchengRewardAd.showAd();
} else {
loadAd();
}
6. 注意事项
需要在平台开启预加载功能。
开启预加载功能后,sdk内部会在广告播放中再次去请求广告
开启预加载功能后,要注意全局使用同一个RewardAd对象。(new注意判null)
广告播放时可先判断isReady(),如果ready直接播放,否则可再次调用loadAdData()。
var JuChengRewardAd rewardVideoAd;//全局对象
/**
* 加载广告
*/
void loadAd() {
if (rewardVideoAd == null) {
JuChengAdRequest request = JuChengAdRequest(pid: pid);
rewardVideoAd = JuChengRewardAd( request:request, listener: listener);
}
rewardVideoAd.loadAdData();
}
五、插屏广告
1. 主要API
JuChengAdRequest
| 参数 | 说明 |
|---|---|
| pid | 广告位 |
| userId | 媒体用户体系ID ,可选 ,默认null |
| options | 扩展参数,默认null |
JuChengInterstitialAd
| 方法 | 说明 |
|---|---|
| JuChengInterstitialAd(required JuChengAdRequest this.request, required JuChengInterstitialListener <JuChengInterstitialAd > this.listener) | 初始化插屏广告对象, request 为广告请求对象,必传, listener 插屏视频接口 必传 |
| loadAdData() | 发起广告加载 |
| isReady() | 判断当前广告是否存在可展示的广告 |
| showAd() | 展示广告 |
| destroy() | 销毁广告 |
JuChengInterstitialListener 插屏广告回调说明
| 回调方法 | 说明 |
|---|---|
| onAdSucceed (JuChengInterstitialAd ad) | 广告加载成功,可在此方法判断isReady后,调用show来展示广告 |
| onAdFailed (JuChengError? error) | 广告加载失败 |
| onAdExposure () | 广告曝光 |
| onAdClicked () | 广告被用户点击 |
| onAdClosed () | 广告关闭 |
2. 创建插屏广告广告对象
JuChengAdRequest request = JuChengAdRequest(pid: pid);
JuChengInterstitialAd intersititialAd = JuChengInterstitialAd( request:request, listener: listener);
3. 设置监听回调
class IJuChengInterstitialListener extends JuChengInterstitialListener<JuChengInterstitialAd> {
void onAdClicked() {
print('onAdClicked');
}
void onAdClose() {
print('onAdClosed');
}
void onAdExposure() {
print('onAdExposure');
}
void onAdFailed(JuChengError error) {
print('onAdFailed: ${error.message}');
}
void onAdSucceed(JuChengInterstitialAd ad) {
print('onAdSucceed');
}
}
4. 插屏广告加载
intersititialAd.loadAdData();
5. 插屏广告播放
bool isReady = await intersititialAd.isReady();
if(isReady){
intersititialAd.showAd();
}
6. 注意事项
平台默认会开启预加载功能。
要注意全局使用同一个InterstitialAd对象。(new注意判null)
广告播放时可先判断isReady(),如果ready直接播放,否则可再次调用loadAdData()。
var JuChengInterstitialAd intersititialAd;//全局对象
/**
* 加载广告
*/
void loadAd() {
if (intersititialAd == null) {
JuChengAdRequest request = JuChengAdRequest(pid: pid);
intersititialAd = JuChengInterstitialAd( request:request, listener: listener);
}
intersititialAd.loadAdData();
}
六、信息流
1. 主要API
JuChengAdRequest
| 参数 | 说明 |
|---|---|
| pid | 广告位 |
| userId | 媒体用户体系ID ,可选 ,默认null |
| options | 扩展参数,默认null |
JuChengNativeAd
| 方法 | 说明 |
|---|---|
| JuChengNativeAd(required AdRequest request, required double width, required double height,required JuChengNativeListener listener) | 初始化信息流广告对象,request 为广告请求对象,必传, listener 信息流广告回调接口 必传 |
| loadAd() | 发起广告 |
| isReady() | 判断当前是否存在可展示的广告 |
| Size? getAdSize() | 获取填充的广告宽高 |
| destroy() | 销毁并关闭广告 |
NativeAdWidget
| 方法 | 说明 |
|---|---|
| NativeAdWidget({Key? key,required this.nativeAd,required this.width,required this.height,this.nativeCustomViewConfig}) | 构造信息流广告Widget对象, nativeAd 信息流广告对象类,必传, width widget宽, height widget 高度 |
| updateAdSize(Size size) | 更新广告Widget 大小 |
JuChengNativeListener 信息流广告回调说明
| 回调方法 | 说明 |
|---|---|
| onAdFailed(JuChengError error) | 广告加载失败 |
| onAdSucceed(JuChengNativeAd ad) | 广告加载成功 |
| onAdExposure() | 广告开始展示 |
| onAdClicked() | 广告被用户点击 |
| onAdRenderSuccess(JuChengNativeAd ad) | 用户广告渲染成功 |
| onAdRenderFail(JuChengError error) | 广告渲染失败 |
| onAdDidDislike(String reason) | dislike 回调,广告被关闭。有穿山甲广告源时,必须在该方法里移除广告 |
CustomNativeAdConfig 信息流广告回调说明
| 静态方法 | 说明 |
|---|---|
| rootView | 广告根视图容器 |
| iconView | 广告主图标 |
| mainAdView | 主广告视图 |
| titleView | 广告标题 |
| descriptView | 广告描述 |
| adLogoView | 广告字样或者广告渠道图标 |
| ctaButton | 广告转化按钮 |
| dislikeButton | 关闭广告按钮 |
| Map createNativeSubViewAttribute( double width, double height, { double x = 0, double y = 0, String backgroundColor = '#FFFFFF', String textColor = '#000000', int fontSize = 0, int scaleType = 0, int textAlignment = 0, bool isCtaClick = false, bool pixel = false } ) | 创建自渲染广告子视图组件属性配置 |
createNativeSubViewAttribute 原生广告自定义组件属性配置
| 属性成员 | 说明 |
|---|---|
| int x | x坐标,相对于父容器,默认值0 |
| int y | y坐标,相对于父容器,默认值0 |
| int width | 宽,默认值0 |
| int height | 高,默认值0 |
| bool pixel | 是否使用像素单位,默认值false |
| String backgroundColor | 背景色(#FFFFFF),默认值空 |
| String textColor | 文字颜色,默认值空 |
| int fontSize | 字体大小,默认0,系统默认 |
| int scaleType | 缩放模式,0,1,2; iOS 0:UIViewContentModeScaleToFill 1:UIViewContentModeScaleAspectFit 2:UIViewContentModeCenter; Android 0:FIT_CENTER 1: FIT_XY 2:CENTER |
| int textAlignment | 文字对齐模式,0,1,2; iOS 0:NSTextAlignmentLeft 1:NSTextAlignmentCenter 2:NSTextAlignmentRight; Android 0:TEXT_ALIGNMENT_INHERIT 1:TEXT_ALIGNMENT_CENTER 2:TEXT_ALIGNMENT_TEXT_END |
| bool isCtaClick | 自定义转化点击,默认false |
2. 创建信息流广告对象
JuChengAdRequest request = JuChengAdRequest(pid: pid);
nativeAd = JuChengNativeAd(
request: request,
listener: listener,
width: 300 ,
height: 200,
);
3. 设置监听回调
class IJuChengNativeListener extends JuChengNativeListener<JuChengNativeAd> {
void onAdFailed(JuChengError error) {
print('onAdFailed');
}
void onAdSucceed(JuChengNativeAd ad) {
print('onAdSucceed');
}
void onAdExposure() {
print('onAdExposure');
}
void onAdRenderFail(JuChengError error) {
print('onAdRenderFail');
}
void onAdRenderSuccess(JuChengNativeAd ad) {
print('onAdRenderSuccess');
}
void onAdClicked() {
print('onAdClicked');
}
void onAdDidDislike(String reason) {
print('onAdDidDislike');
}
}
4. 信息流广告加载
nativeAd.loadAd();
5. 信息流广告自定义View播放
bool isReady = await nativeAd.isReady();
if(!isReady) return;
NativeAdWidget nativeAdWidget = NativeAdWidget(
nativeAd: ad,
height: 350,
width: 300,
nativeCustomViewConfig: {
CustomNativeAdConfig.rootView(): CustomNativeAdConfig.createNativeSubViewAttribute(
300, 350,
x: 50,
y: 350,
backgroundColor: '#FFFFFF'
),
CustomNativeAdConfig.iconView(): CustomNativeAdConfig.createNativeSubViewAttribute(
50, 50,
x: 10, y: 40,),
CustomNativeAdConfig.titleView(): CustomNativeAdConfig.createNativeSubViewAttribute(
200,
20,
x: 60,
y: 210,
fontSize: 15,
),
CustomNativeAdConfig.descriptView(): CustomNativeAdConfig.createNativeSubViewAttribute(
230, 20,
x: 60, y:230, fontSize: 15),
CustomNativeAdConfig.ctaButton(): CustomNativeAdConfig.createNativeSubViewAttribute(
100,
50,
x:20,
y: 265,
fontSize: 15,
textColor: "#FFFFFF",
backgroundColor: "#2095F1"
),
CustomNativeAdConfig.mainAdView(): CustomNativeAdConfig.createNativeSubViewAttribute(
290, 200,
x: 5, y: 5, backgroundColor: '#00000000'),
CustomNativeAdConfig.adLogoView(): CustomNativeAdConfig.createNativeSubViewAttribute(
20, 10,
x: 10,
y: 10,
backgroundColor: '#00000000'),
CustomNativeAdConfig.dislikeButton(): CustomNativeAdConfig.createNativeSubViewAttribute(
20,
20,
x:260,
y: 210,
),
},
);
6. 注意事项
穿山甲信息流关闭时,需要在onAdDidDislike(String reason)回调方法里,主动remove掉广告,否则有些广告会无法关闭,影响收益。
七、Banner广告
1. 主要API
JuChengAdRequest
| 参数 | 说明 |
|---|---|
| pid | 广告位 |
| userId | 媒体用户体系ID ,可选 ,默认null |
| options | 扩展参数,默认null |
JuChengBannerAd
| 方法 | 说明 |
|---|---|
| JuChengBannerAd(required AdRequest request, required double width, required double height,required JuChengBannerListener listener) | 初始化banner广告对象,request 为广告请求对象,必传, listener 横幅广告回调接口 必传 |
| loadAd() | 发起广告 |
| isReady() | 判断当前BannerAd是否存在可展示的广告 |
| destroy() | 销毁并关闭广告 |
BannerAdWidget
| 方法 | 说明 |
|---|---|
| BannerAdWidget({ required this.juchengBannerAd, double this.width = 320, double this.height = 50}) | 构造横幅广告Widget对象, juchengBannerAd 横幅广告对象类,必传, width widget宽, height widget 高度 |
| updateAdSize(Size size) | 更新广告Widget 大小 |
JuChengBannerListener
| 回调方法 | 说明 |
|---|---|
| onAdFailed(JuChengError error) | 广告加载失败 |
| onAdSucceed(JuChengBannerAd ad) | 广告加载成功 |
| onAdExposure() | 广告开始展示 |
| onAdShowError(JuChengBannerAd ad, JuChengError error) | 广告开始展示失败 |
| onAdClicked() | 广告被用户点击 |
| onAdClose() | 广告关闭 |
| onAdAutoRefreshed(JuChengBannerAd ad) | 自动刷新广告成功 |
| onAdAutoRefreshFail(JuChengBannerAd ad, JuChengError error) | 自动刷新广告失败 |
2. 创建bannler广告对象
JuChengAdRequest request = JuChengAdRequest(pid: "pid");
JuChengBannerAd bannerAd = JuChengBannerAd(request: request,width: 300,height: 100, listener: IJuChengBannerListener());
3. 设置监听回调
class IJuChengBannerListener extends JuChengBannerListener<JuChengBannerAd> {
void onAdAutoRefreshFail(JuChengBannerAd ad, JuChengError error) {
print('flu-banner --- onAdAutoRefreshFail: ${error.message}');
}
void onAdAutoRefreshed(JuChengBannerAd ad) {
print('#############Interstitial onAdSucceed');
}
void onAdShowError(JuChengBannerAd ad, JuChengError error) {
print('flu-banner --- onAdShowError: ${error.message}');
}
vvoid onAdShowError(JuChengBannerAd ad, JuChengError error) {
print('flu-banner --- onAdShowError: ${error.message}');
}
void onAdClose() {
print('flu-banner --- onAdClose');
}
void onAdExposure() {
print('flu-banner --- onAdExposure');
}
void onAdFailed(JuChengError error) {
print('flu-banner --- onAdFailed');
}
void onAdSucceed(JuChengBannerAd ad) {
print('flu-banner --- onAdSucceed');
}
}
4. bannler广告加载
bannerAd.loadAd();
5. bannler广告播放
bool isReady = await bannerAd.isReady();
if(isReady){
BannerAdWidget bannerAdWidget = BannerAdWidget(
juchengBannerAd: bannerAd,
height: 50,
width: 320,
);
}