当我调用RewardedVideoAd时,我尝试重新加载奖励视频广告。例子加载(起始代码:“xxx”,目标信息:xyz)
我发现以下错误:
W/MessageQueue(13672): Handler(android.os.Handler){1a13e8a}向死线程上的Handler发送消息W/MessageQueue(13672):java.lang.IllegalStateExc0019: Handler(android.os.Handler){1a13e8a}向死线程上的Handler发送消息线程W/MessageQueue(13672):在android.os.MessageQueue.enqueueMessage(MessageQueue.java:543)W/MessageQueue(13672):在android.os.Handler.enqueueMessage(Handler.java:643)W/MessageQueue(13672):在android.os.Handler.sendMessageAtTime(Handler.java:612)W/MessageQueue(13672):在android.os.Handler.sendMessageDelayed(Handler. java: 582)W/MessageQueue(13672):在android. os.在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. interal. 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. interal. webview. tE(:com.google.android.gms.policy_ads_fdr_dynamite@20300003@20300003.251657827.251657827:5)W/MessageQueue(13672): at com. google. android. gms. ads. interal. webview. j. onPageFinated(: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.调度消息(Handler. java: 102)W/MessageQueue(13672): at android. os.循环(Loop. java: 154)W/MessageQueue(13672): at android. app.ActivityThread. main(ActivityThread. java: 6780)W/MessageQueue(13672):在java. lang.反射。方法调用(本地方法)W/MessageQueue(13672):在com. android. interal. os。ZygoteInit$method odAndArgsCaller. run(ZygoteInit. java: 1496)W/MessageQueue(13672):在com. android. interal. os。ZygoteInit. main(ZygoteInit. java: 1386)W/ExoPlayerIMInID(13672):发布后发送消息(1)。消息忽略。D/图形(13672):RemveVertex():插入DummyVertex,因为没有祖先。D/ViewRootImpl@b8db50eAdActivity:mHardware Renderer.销毁()#4 D/ViewRootImpl@b8db50eAdActivity:调度DetachedFromWindow
我将侦听器放在屏幕的
initState()
中。在这个屏幕上我有一个按钮
,如果我们点击它,它会显示奖励视频广告
。
此外,得到错误后,当
Rewarded Ads
重新加载,我得到下面的错误后,点击按钮显示广告(因为广告实例为空):
E/flutter(13672):[ERROR: flutter/lib/ui/ui_dart_state.cc(148)]未处理的异常:平台异常(ad_not_loaded,奖励视频显示失败,没有广告加载,空)E/flutter(13672):#0标准方法odec.decode信封(包:flutter/src/service/message_codecs.dart:564: 7)E/flutter(13672):#1方法hannel.invoke方法(包: flutter/src/service/platform_channel.dart:316: 33)E/flutter(13672): E/flutter(13672):#2_invokeBooleanMethod(包:firebase_admob/firebase_admob.dart:518: 61)E/flutter(13672): E/flutter(13672):#3奖励视频d.show(包:firebase_admob/firebase_admob.dart:392: 12)
我在
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);
});
}
};
...
但是,如果我把代码在按钮的
onPmed
像下面一样,视频广告将显示后点击2-3次(其中在调试是showads=null
)
RaisedButton(
onPressed: () {
RewardedVideoAd.instance.show().whenComplete(() {
RewardedVideoAd.instance.load(adUnitId: "ca-app-pub-3940256099942544/5224354917", targetingInfo: targetingInfos);
})
},
...
有什么想法吗?
先谢谢你。。。
您只需捕获异常,如下所示:
myRewardVideoAd.show()
.catchError((e) => print("error in showing ad: ${e.toString()}"));
不需要调用set state,因为它很昂贵,并且会导致完全重建。
可以通过以下方式轻松解决此问题:
import 'package:flutter/material.dart';
import 'package:firebase_admob/firebase_admob.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: HomePage());
}
}
class HomePage extends StatefulWidget {
HomePage({Key key}) : super(key: key);
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
//The targeting info required for Rewarded Videos Ads
MobileAdTargetingInfo targetingInfo = MobileAdTargetingInfo(
keywords: <String>['flutterio', 'beautiful apps'],
contentUrl: 'https://flutter.io',
childDirected: false,
testDevices: <String>[], // Android emulators are considered test devices
);
//An instance to be called in the init state
RewardedVideoAd _videoAd = RewardedVideoAd.instance;
@override
void initState() {
//---------------------------------------//
//Initialise the listener with the values.
_videoAd.listener =
(RewardedVideoAdEvent event, {String rewardType, int rewardAmount}) {
if (event == RewardedVideoAdEvent.completed) {
//When the video ad gets completed load a new video ad
_videoAd
.load(
adUnitId: RewardedVideoAd.testAdUnitId,
targetingInfo: targetingInfo)
.catchError((e) => print('Error in loading.'));
}
//On every other event change pass the values to the _handleEvent Method.
_handleEvent(event, rewardType, 'Reward', rewardAmount);
};
//------------------------------------------------------------------//
//This will load the video when the widget is built for the first time.
_videoAd
.load(
adUnitId: RewardedVideoAd.testAdUnitId,
targetingInfo: targetingInfo)
.catchError((e) => print('Error in loading.'));
//-----------------------------------------------------//
super.initState();
}
//---- Useful function to know exactly what is being done ----//
void _handleEvent(RewardedVideoAdEvent event, String rewardType,
String adType, int rewardAmount) {
switch (event) {
case RewardedVideoAdEvent.loaded:
_showSnackBar('New Admob $adType Ad loaded!', 1500);
break;
case RewardedVideoAdEvent.opened:
_showSnackBar('Admob $adType Ad opened!', 1500);
break;
//
//The way we are fixing the issue is here.
//This is by calling the video to be loaded when the other rewarded video is closed.
case RewardedVideoAdEvent.closed:
_showSnackBar('Admob $adType Ad closed!', 1500);
_videoAd
.load(
adUnitId: RewardedVideoAd.testAdUnitId,
targetingInfo: targetingInfo)
.catchError((e) => print('Error in loading.'));
break;
case RewardedVideoAdEvent.failedToLoad:
_showSnackBar('Admob $adType failed to load.', 1500);
break;
case RewardedVideoAdEvent.rewarded:
_showSnackBar('Rewarded $rewardAmount', 3000);
break;
default:
}
}
//Snackbar shown with ad status
void _showSnackBar(String content, int duration) {
Scaffold.of(context).showSnackBar(SnackBar(
content: Text(content),
duration: Duration(milliseconds: duration),
));
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: FlatButton(
child: Text('Play AD'),
onPressed: () {
_videoAd.show().catchError(
(e) => print("error in showing ad: ${e.toString()}"));
},
),
),
);
}
}
似乎问题在于事件已完成
。查看此代码。
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);
},
),
);
}
我正在尝试使用Admob在我的android应用程序中显示奖励视频广告。如果我用谷歌示例广告单元ID运行应用程序,它工作得很好,但如果我将其更改为我的奖励广告单元ID,则不会加载广告。
我正在尝试整合Facebook奖励视频。但是在获得放置ID时,奖励视频没有放置位置。只有本机、横幅、间隙和中矩形。我正在使用Facebook文档中的这些步骤 我的logcat给出以下错误: 05-25 18:27:22.530 6932-6932奖励视频广告加载失败:广告请求中的显示格式与为此放置指定的显示格式不匹配。每个放置只能与一种显示格式一起使用。您可以创建多个放置以使用多种显示格式。
我已经发布了一个iOS应用程序,但我在使用谷歌移动广告SDK加载奖励视频广告时遇到了问题。 当玩家点击按钮查看视频广告时,玩家很少会看到视频。大多数时候,用户会看到Admob无法填写请求的错误: 有时,他们需要点击几下才能获得一个,有时,无论点击多少次,他们都无法获得一个。这个问题更多发生在我的奖励视频中,但也发生在我的横幅广告中。有时谷歌无法为我提供横幅广告。有人知道为什么这不起作用吗? 我的广
我正在尝试使用AdMob显示奖励视频广告。我添加了2个广告网络(AdColony、InMobi)并提供了所有必需的详细信息,如帐户ID等。 我还下载并编译了所需的网络SDK和适配器。 广告代码: 问题是我总是从AdMob那里得到同样的回应: 获取广告回复时出现问题。错误代码:0 有什么办法解决这个问题吗? 更新: 我通过从AdRequest中删除“addTestDevice()”克服了加载广告的问
在用户关闭间隙广告后,我将在我的应用程序中添加奖励广告,它将显示一个屏幕,显示之前输入的文本,并在下方有一个显示奖励广告的视频按钮(我处于测试阶段,因此我还不包括任何奖励项目,只想先显示视频广告)。 当我使用Toast小部件来识别广告是否已加载时,我意识到广告已加载(显示“onRewardedAdLoade”文本)。但是,当我单击观看视频按钮时,似乎没有调用show RewardedVideo()
我在Unity3d中显示admob插件的奖励视频广告时遇到问题。首先,这是我的脚本: 我用一个按钮运行RequestRewardVideo()方法,但什么也没发生。我尝试运行按钮中的和中的方法,但只显示了视频1/3次。。。这个怎么了? 提前感谢