-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fde4ebf
commit eaa2cc6
Showing
4 changed files
with
83 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 68 additions & 59 deletions
127
ohos/src/main/ets/components/plugin/FlutterUnionadPlugin.ets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,86 @@ | ||
import { | ||
FlutterPlugin, | ||
FlutterPluginBinding, | ||
MethodCall, | ||
MethodCallHandler, | ||
MethodChannel, | ||
MethodResult, | ||
FlutterPlugin, | ||
FlutterPluginBinding, | ||
MethodCall, | ||
MethodCallHandler, | ||
MethodChannel, | ||
MethodResult, | ||
} from '@ohos/flutter_ohos'; | ||
import { | ||
CSJAdSdk, | ||
SDKConfig, | ||
SDKConfigBuilder | ||
AdLoadType, | ||
AdSlotBuilder, CSJAdSdk, | ||
CSJRewardAd, | ||
RewardAdLoadListener, SDKConfig, | ||
SDKConfigBuilder | ||
} from '@csj/openadsdk'; | ||
|
||
/** FlutterUnionadPlugin **/ | ||
export default class FlutterUnionadPlugin implements FlutterPlugin, MethodCallHandler { | ||
private channel: MethodChannel | null = null; | ||
private applicationContext: Context | null = null; | ||
|
||
constructor() { | ||
} | ||
|
||
getUniqueClassName(): string { | ||
return "FlutterUnionadPlugin" | ||
} | ||
private channel: MethodChannel | null = null; | ||
private applicationContext: Context | null = null; | ||
private adCreator = CSJAdSdk.getAdCreator(); | ||
constructor() { | ||
} | ||
|
||
onAttachedToEngine(binding: FlutterPluginBinding): void { | ||
this.channel = new MethodChannel(binding.getBinaryMessenger(), "flutter_unionad"); | ||
this.channel.setMethodCallHandler(this) | ||
this.applicationContext = binding.getApplicationContext(); | ||
} | ||
getUniqueClassName(): string { | ||
return "FlutterUnionadPlugin" | ||
} | ||
|
||
onDetachedFromEngine(binding: FlutterPluginBinding): void { | ||
if (this.channel != null) { | ||
this.channel.setMethodCallHandler(null) | ||
onAttachedToEngine(binding: FlutterPluginBinding): void { | ||
this.channel = new MethodChannel(binding.getBinaryMessenger(), "flutter_unionad"); | ||
this.channel.setMethodCallHandler(this) | ||
this.applicationContext = binding.getApplicationContext(); | ||
} | ||
} | ||
|
||
onMethodCall(call: MethodCall, result: MethodResult): void { | ||
if (call.method == "register") { | ||
onDetachedFromEngine(binding: FlutterPluginBinding): void { | ||
if (this.channel != null) { | ||
this.channel.setMethodCallHandler(null) | ||
} | ||
} | ||
|
||
// 创建SDKConfig对象 | ||
let adConfigBuilder = new SDKConfigBuilder() | ||
let config: SDKConfig = adConfigBuilder | ||
.appId("5638354") | ||
.appName("穿山甲Demo") | ||
.allowShowNotify(true) | ||
.debug(true) | ||
.build() | ||
onMethodCall(call: MethodCall, result: MethodResult): void { | ||
if (call.method == "register") { | ||
|
||
// 初始化SDK | ||
CSJAdSdk.init(this.applicationContext, config) //context类型必须为UIAbility,否则可能存在展示异常场景 | ||
// 创建SDKConfig对象 | ||
let adConfigBuilder = new SDKConfigBuilder() | ||
let config: SDKConfig = adConfigBuilder | ||
.appId("5638354") | ||
.appName("穿山甲Demo") | ||
.allowShowNotify(true) | ||
.debug(true) | ||
.build() | ||
|
||
// 启动SDK | ||
CSJAdSdk.start(); | ||
result.success(true) | ||
}else if (call.method == "getSDKVersion") { | ||
// 创建SDKConfig对象 | ||
let adConfigBuilder = new SDKConfigBuilder() | ||
let config: SDKConfig = adConfigBuilder | ||
.appId("5638354") | ||
.appName("穿山甲Demo") | ||
.allowShowNotify(true) | ||
.debug(true) | ||
.build() | ||
// 初始化SDK | ||
CSJAdSdk.init(this.applicationContext, config) //context类型必须为UIAbility,否则可能存在展示异常场景 | ||
|
||
// 初始化SDK | ||
CSJAdSdk.init(this.applicationContext, config) //context类型必须为UIAbility,否则可能存在展示异常场景 | ||
// 启动SDK | ||
CSJAdSdk.start(); | ||
result.success(true) | ||
} else if (call.method == "getSDKVersion") { | ||
result.success(CSJAdSdk.getSDKVersion()) | ||
} else if (call.method == "getThemeStatus") { | ||
result.success(0) | ||
} else if (call.method == "loadRewardVideoAd") { | ||
|
||
// 启动SDK | ||
CSJAdSdk.start(); | ||
result.success(true) | ||
} else { | ||
result.notImplemented() | ||
let adSlot = new AdSlotBuilder() | ||
.setCodeId("codeId") | ||
.setAdLoadType(AdLoadType.LOAD) | ||
// .setMediaExtra(mediaExtra) | ||
.build() | ||
let mLoadListener: RewardAdLoadListener = { | ||
onAdLoaded: (rewardAd: CSJRewardAd) => { | ||
// 广告基础信息加载完成 | ||
}, | ||
onAdCached: (rewardAd: CSJRewardAd) => { | ||
// 广告基础信息与素材缓存完成 | ||
}, | ||
onError: (code: number, message: string) => { | ||
} | ||
} | ||
this.adCreator.loadRewardAd(adSlot, mLoadListener) | ||
result.success(true) | ||
} else { | ||
result.notImplemented() | ||
} | ||
} | ||
} | ||
} |