Skip to content

Commit

Permalink
android 升级sdk 4.400.1270
Browse files Browse the repository at this point in the history
优化除信息流之外曝光问题
  • Loading branch information
gstory0404 committed Sep 3, 2021
1 parent 8ab289f commit 7593b2b
Show file tree
Hide file tree
Showing 17 changed files with 160 additions and 59 deletions.
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ android {

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.qq.e.union:union:4.380.1250'
implementation 'com.qq.e.union:union:4.400.1270'
}
11 changes: 10 additions & 1 deletion android/src/main/kotlin/com/gstory/flutter_tencentad/UIUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ import java.lang.reflect.InvocationTargetException
* @CreateDate: 2021/8/7 18:03
**/
object UIUtils {

fun getScreenWidth(context: Context): Int {
return context.resources.displayMetrics.widthPixels
}

fun getScreenHeight(context: Context): Int {
return getRealHeight(context)
}

fun getScreenWidthDp(context: Context): Float {
val scale = context.resources.displayMetrics.density.toFloat()
val width = context.resources.displayMetrics.widthPixels.toFloat()
Expand All @@ -22,7 +31,7 @@ object UIUtils {
}

//全面屏、刘海屏适配
fun getHeight(activity: Activity): Float {
fun getHeightDp(activity: Activity): Float {
hideBottomUIMenu(activity)
val height: Float
val realHeight = getRealHeight(activity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package com.gstory.flutter_tencentad.bannerad

import android.app.Activity
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import com.gstory.flutter_tencentad.FlutterTencentAdConfig
import com.gstory.flutter_tencentad.LogUtil
import com.gstory.flutter_tencentad.UIUtils
import com.qq.e.ads.banner2.UnifiedBannerADListener
import com.qq.e.ads.banner2.UnifiedBannerView
import com.qq.e.comm.util.AdError
Expand Down Expand Up @@ -48,15 +48,14 @@ internal class BannerAdView(
viewWidth = width.toFloat()
viewHeight = height.toFloat()
mContainer = FrameLayout(activity)
mContainer?.layoutParams?.width = UIUtils.dip2px(activity, viewWidth).toInt()
mContainer?.layoutParams?.height = UIUtils.dip2px(activity, viewHeight).toInt()
mContainer?.layoutParams?.width = ViewGroup.LayoutParams.WRAP_CONTENT
mContainer?.layoutParams?.height = ViewGroup.LayoutParams.WRAP_CONTENT
channel = MethodChannel(messenger, FlutterTencentAdConfig.bannerAdView + "_" + id)
loadBannerAd()
}

private fun loadBannerAd() {
unifiedBannerView = UnifiedBannerView(activity, codeId, this)
mContainer?.addView(unifiedBannerView)
unifiedBannerView?.loadAD()
}

Expand All @@ -74,6 +73,7 @@ internal class BannerAdView(

//广告加载成功回调,表示广告相关的资源已经加载完毕,Ready To Show
override fun onADReceive() {
mContainer?.addView(unifiedBannerView)
LogUtil.e("$TAG Banner广告加载成功回调")
channel?.invokeMethod("onShow", "")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ package com.gstory.flutter_tencentad.expressad

import android.app.Activity
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import com.gstory.flutter_tencentad.FlutterTencentAdConfig
import com.gstory.flutter_tencentad.LogUtil
import com.gstory.flutter_tencentad.UIUtils
import com.qq.e.ads.banner2.UnifiedBannerADListener
import com.qq.e.ads.banner2.UnifiedBannerView
import com.qq.e.ads.cfg.DownAPPConfirmPolicy
import com.qq.e.ads.cfg.VideoOption
import com.qq.e.ads.nativ.ADSize
import com.qq.e.ads.nativ.NativeExpressAD
Expand Down Expand Up @@ -51,8 +50,8 @@ internal class NativeExpressAdView(
viewWidth = params["viewWidth"] as Int
viewHeight = params["viewHeight"] as Int
mContainer = FrameLayout(activity)
mContainer?.layoutParams?.width = UIUtils.dip2px(activity, viewWidth.toFloat()).toInt()
mContainer?.layoutParams?.height = UIUtils.dip2px(activity, viewHeight.toFloat()).toInt()
mContainer?.layoutParams?.width = ViewGroup.LayoutParams.WRAP_CONTENT
mContainer?.layoutParams?.height = ViewGroup.LayoutParams.WRAP_CONTENT
channel = MethodChannel(messenger, FlutterTencentAdConfig.nativeExpressAdView + "_" + id)
loadExpressAd()
}
Expand All @@ -68,17 +67,18 @@ internal class NativeExpressAdView(
}
nativeExpressAD = NativeExpressAD(activity, adSize, codeId, this)
nativeExpressAD?.setVideoOption(VideoOption.Builder()
.setAutoPlayPolicy(VideoOption.AutoPlayPolicy.WIFI)
.setAutoPlayPolicy(VideoOption.AutoPlayPolicy.ALWAYS)
.setAutoPlayMuted(true)
.build())
nativeExpressAD?.setDownAPPConfirmPolicy(DownAPPConfirmPolicy.Default)
nativeExpressAD?.loadAD(1)
}

override fun getView(): View {
return mContainer!!
}

/**************平台模板广告加载、渲染、点击状态的回调。****************/
/**************平台模板广告加载、渲染、点击状态的回调。****************/

//无广告填充
override fun onNoAD(p0: AdError?) {
Expand All @@ -91,21 +91,27 @@ internal class NativeExpressAdView(
// 但是想让广告曝光还需要调用 NativeExpressADView 的 render 方法
override fun onADLoaded(p0: MutableList<NativeExpressADView>?) {
LogUtil.e("广告数据加载成功")
// 释放前一个 NativeExpressADView 的资源
if (nativeExpressAdView != null) {
nativeExpressAdView?.destroy()
}
nativeExpressAdView = p0!![0]
if (nativeExpressAdView?.boundData?.adPatternType == AdPatternType.NATIVE_VIDEO) {
nativeExpressAdView?.setMediaListener(this)
}
mContainer?.removeAllViews()
mContainer?.addView(nativeExpressAdView)
nativeExpressAdView?.render()
if(mContainer?.childCount != 0){
mContainer?.removeAllViews()
}
mContainer?.addView(nativeExpressAdView,0)
}

//NativeExpressADView 渲染广告失败
override fun onRenderFail(p0: NativeExpressADView?) {
LogUtil.e("渲染广告失败")
var map: MutableMap<String, Any?> = mutableMapOf("code" to 0, "message" to "渲染广告失败")
channel?.invokeMethod("onFail", map)
p0?.destroy()
nativeExpressAdView?.destroy()
}

//NativeExpressADView 渲染广告成功
Expand Down Expand Up @@ -148,7 +154,7 @@ internal class NativeExpressAdView(
LogUtil.e("广告关闭遮盖时调用")
}

/*****************平台模板视频广告播放状态回调接口,专用于带有视频素材的广告对象**************/
/*****************平台模板视频广告播放状态回调接口,专用于带有视频素材的广告对象**************/

//视频播放 View 初始化完成
override fun onVideoInit(p0: NativeExpressADView?) {
Expand All @@ -163,11 +169,13 @@ internal class NativeExpressAdView(
//视频下载完成
override fun onVideoCached(p0: NativeExpressADView?) {
LogUtil.e("视频下载完成")
// nativeExpressAdView?.
}

//视频播放器初始化完成,准备好可以播放了,videoDuration 是视频素材的时间长度,单位为 ms
override fun onVideoReady(p0: NativeExpressADView?, p1: Long) {
LogUtil.e("视频播放器初始化完成")
// nativeExpressAdView?
}

//视频开始播放
Expand Down Expand Up @@ -203,9 +211,7 @@ internal class NativeExpressAdView(

override fun dispose() {
nativeExpressAdView?.destroy()
nativeExpressAdView = null
mContainer?.removeAllViews()
mContainer = null
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ object InterstitialAd {
codeId,
interstitialADListener
)
// unifiedInterstitialAD?.setMediaListener(this)
if(isFullScreen!!){
unifiedInterstitialAD?.loadFullScreenAD()
}else{
Expand All @@ -46,6 +47,16 @@ object InterstitialAd {
LogUtil.e("$TAG 插屏全屏视频广告显示失败,无广告")
return
}
// 广告是否有效,无效广告将无法展示
if(!unifiedInterstitialAD?.isValid!!){
var map: MutableMap<String, Any?> = mutableMapOf("adType" to "interactAd","onAdMethod" to "onFail","code" to 1 , "message" to "插屏全屏视频视频广告显示失败,无效广告")
FlutterTencentAdEventPlugin.sendContent(map)
LogUtil.e("$TAG 插屏全屏视频广告显示失败,无效广告")
unifiedInterstitialAD?.close()
unifiedInterstitialAD?.destroy()
unifiedInterstitialAD = null
return
}
if(isFullScreen!!){
unifiedInterstitialAD?.showFullScreenAD(context)
}else{
Expand All @@ -57,8 +68,6 @@ object InterstitialAd {
//插屏全屏视频广告加载完毕,此回调后才可以调用 show 方法
override fun onADReceive() {
LogUtil.e("$TAG 插屏全屏视频广告加载完毕")
var map: MutableMap<String, Any?> = mutableMapOf("adType" to "interactAd","onAdMethod" to "onReady")
FlutterTencentAdEventPlugin.sendContent(map)
}

//插屏全屏视频视频广告,视频素材下载完成
Expand Down Expand Up @@ -111,6 +120,8 @@ object InterstitialAd {
// 插屏全屏视频视频广告,渲染成功
override fun onRenderSuccess() {
LogUtil.e("$TAG 插屏全屏视频视频广告,渲染成功")
var map: MutableMap<String, Any?> = mutableMapOf("adType" to "interactAd","onAdMethod" to "onReady")
FlutterTencentAdEventPlugin.sendContent(map)
}

//插屏全屏视频视频广告,渲染失败
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package com.gstory.flutter_tencentad.splashad
import android.app.Activity
import android.util.Log
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import com.gstory.flutter_tencentad.FlutterTencentAdConfig
import com.gstory.flutter_tencentad.LogUtil
import com.gstory.flutter_tencentad.UIUtils
import com.qq.e.ads.splash.SplashAD
import com.qq.e.ads.splash.SplashADListener
import com.qq.e.comm.util.AdError
Expand Down Expand Up @@ -35,6 +37,8 @@ internal class SplashAdView(
codeId = params["codeId"] as String
fetchDelay = params["fetchDelay"] as Int
mContainer = FrameLayout(activity)
mContainer?.layoutParams?.width = ViewGroup.LayoutParams.WRAP_CONTENT
mContainer?.layoutParams?.height = ViewGroup.LayoutParams.WRAP_CONTENT
channel = MethodChannel(messenger, FlutterTencentAdConfig.splashAdView + "_" + id)
loadSplashAd()
}
Expand Down
5 changes: 5 additions & 0 deletions error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
* The 'Pods-Runner' target has transitive dependencies that include statically linked binaries
```
[!] The 'Pods-Runner' target has transitive dependencies that include statically linked binaries: (/Users/xx/mywork/my/flutter_tencentad/example/ios/Pods/GDTMobSDK/lib/libGDTMobSDK.a)
```
打开iOS目录下的Podfile,删除掉use_frameworks!,重新build
4 changes: 2 additions & 2 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ android {
debug {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
// signingConfig signingConfigs.config
signingConfig signingConfigs.config
}
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
// signingConfig signingConfigs.config
signingConfig signingConfigs.config
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.gstory.flutter_tencentad_example">

<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" />

<application
android:label="flutter_tencentad_example"
android:icon="@mipmap/ic_launcher">

<activity
android:name=".MainActivity"
android:launchMode="singleTop"
Expand Down
Loading

0 comments on commit 7593b2b

Please sign in to comment.