gpt4 book ai didi

android - flutter - 重新加载时奖励视频广告错误 : "ad_not_loaded, show failed for rewarded video, no ad was loaded, null)"

转载 作者:IT王子 更新时间:2023-10-29 07:16:32 32 4
gpt4 key购买 nike

我尝试重新加载奖励视频广告,当我调用 RewardedVideoAd.instance.load(adUnitId: "xxx", targetingInfo: xyz); 我发现以下错误:

W/MessageQueue(13672): Handler (android.os.Handler) {1a13e8a} sending message to a Handler on a dead thread W/MessageQueue(13672): java.lang.IllegalStateException: Handler (android.os.Handler) {1a13e8a} sending message to a Handler on a dead thread W/MessageQueue(13672): at android.os.MessageQueue.enqueueMessage(MessageQueue.java:543) W/MessageQueue(13672): at android.os.Handler.enqueueMessage(Handler.java:643) W/MessageQueue(13672): at android.os.Handler.sendMessageAtTime(Handler.java:612) W/MessageQueue(13672): at android.os.Handler.sendMessageDelayed(Handler.java:582) W/MessageQueue(13672): at android.os.Handler.sendEmptyMessageDelayed(Handler.java:546) W/MessageQueue(13672): at android.os.Handler.sendEmptyMessage(Handler.java:531) W/MessageQueue(13672): at com.google.android.gms.ads.exoplayer1.h.c(:com.google.android.gms.policy_ads_fdr_dynamite@20300003@20300003.251657827.251657827:2) W/MessageQueue(13672): at com.google.android.gms.ads.internal.video.exoplayer1.f.b(:com.google.android.gms.policy_ads_fdr_dynamite@20300003@20300003.251657827.251657827:1) W/MessageQueue(13672): at com.google.android.gms.ads.internal.webview.t.E(:com.google.android.gms.policy_ads_fdr_dynamite@20300003@20300003.251657827.251657827:5) W/MessageQueue(13672): at com.google.android.gms.ads.internal.webview.j.onPageFinished(:com.google.android.gms.policy_ads_fdr_dynamite@20300003@20300003.251657827.251657827:2) W/MessageQueue(13672): at uU.d(PG:307) W/MessageQueue(13672): at aIV.handleMessage(PG:73) W/MessageQueue(13672): at android.os.Handler.dispatchMessage(Handler.java:102) W/MessageQueue(13672): at android.os.Looper.loop(Looper.java:154) W/MessageQueue(13672): at android.app.ActivityThread.main(ActivityThread.java:6780) W/MessageQueue(13672): at java.lang.reflect.Method.invoke(Native Method) W/MessageQueue(13672): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496) W/MessageQueue(13672): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386) W/ExoPlayerImplInternal(13672): Sent message(1) after release. Message ignored. D/Graph (13672): removeVertex() : insertDummyVertex, because there is no ancestor. D/ViewRootImpl@b8db50eAdActivity: mHardwareRenderer.destroy()#4 D/ViewRootImpl@b8db50eAdActivity: dispatchDetachedFromWindow

我将监听器放在屏幕的 initState() 中。在此屏幕中,我有一个按钮,如果我们点击它,它应该显示 奖励视频广告

此外,在 Rewarded Ads 重新加载时出现错误后,我在点击按钮显示广告后出现以下错误(因为广告实例为 null):

E/flutter (13672): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: PlatformException(ad_not_loaded, show failed for rewarded video, no ad was loaded, null) E/flutter (13672): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:564:7) E/flutter (13672): #1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:316:33) E/flutter (13672): E/flutter (13672): #2 _invokeBooleanMethod (package:firebase_admob/firebase_admob.dart:518:61) E/flutter (13672): E/flutter (13672): #3 RewardedVideoAd.show (package:firebase_admob/firebase_admob.dart:392:12)

我将 Rewarded Video Ads Listener 放在 initState() 中,下面是代码:

@override
void initState() {
super.initState();
...
RewardedVideoAd.instance.listener =
(RewardedVideoAdEvent event, {String rewardType, int rewardAmount}) {
if (event == RewardedVideoAdEvent.completed) {
setState(() {
print ("::debug:: ads should be reloaded");
RewardedVideoAd.instance.load(adUnitId: "ca-app-pub-3940256099942544/5224354917", targetingInfo: targetingInfos);
});
}
};
...

但是,如果我将代码放在按钮的 onPressed 上,如下所示,视频广告将在点击 2-3 次后显示(调试时显示 广告 = null)

RaisedButton(
onPressed: () {
RewardedVideoAd.instance.show().whenComplete(() {
RewardedVideoAd.instance.load(adUnitId: "ca-app-pub-3940256099942544/5224354917", targetingInfo: targetingInfos);
})
},
...

有什么想法吗?

提前致谢...

最佳答案

问题似乎出在事件 completed 上。查看此代码。

MobileAdTargetingInfo targetingInfo = MobileAdTargetingInfo(
keywords: <String>['flutterio', 'beautiful apps'],
contentUrl: 'https://flutter.io',
childDirected: false,
testDevices: <String>[], // Android emulators are considered test devices
);
bool _loaded = false;

@override
void initState() {
super.initState();

// load ad in the beginning
RewardedVideoAd.instance
.load(adUnitId: RewardedVideoAd.testAdUnitId, targetingInfo: targetingInfo)
.catchError((e) => print("error in loading 1st time"))
.then((v) => setState(() => _loaded = v));

// ad listener
RewardedVideoAd.instance.listener = (RewardedVideoAdEvent event, {String rewardType, int rewardAmount}) {
if (event == RewardedVideoAdEvent.closed) {
RewardedVideoAd.instance
.load(adUnitId: RewardedVideoAd.testAdUnitId, targetingInfo: targetingInfo)
.catchError((e) => print("error in loading again"))
.then((v) => setState(() => _loaded = v));
}
};
}


@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Text(
"Loaded = ${_loaded}",
style: TextStyle(fontSize: 32, fontWeight: FontWeight.bold),
),
),
floatingActionButton: FloatingActionButton(
// show ad on FAB click
onPressed: () async {
await RewardedVideoAd.instance.show().catchError((e) => print("error in showing ad: ${e.toString()}"));
setState(() => _loaded = false);
},
),
);
}

关于android - flutter - 重新加载时奖励视频广告错误 : "ad_not_loaded, show failed for rewarded video, no ad was loaded, null)",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57212679/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com