英文:
Interstitial ads not showing in Flutter
问题
我正在使用这个包: https://pub.dev/packages/firebase_admob
一切都设置正确,正常的横幅广告显示正常。我的问题仅出现在插页式广告上:
import 'package:firebase_admob/firebase_admob.dart';
BannerAd myBanner = BannerAd(
adUnitId: BannerAd.testAdUnitId,
size: AdSize.smartBanner,
listener: (MobileAdEvent event) {
print("BannerAd event is $event");
},
);
InterstitialAd myInterstitial = InterstitialAd(
adUnitId: 'ca-app-pub-MYID',
listener: (MobileAdEvent event) {
print("InterstitialAd event is $event");
},
);
class Ads {
static showBanner() {
myBanner
// 通常在广告显示之前会发生这种情况
..load()
..show(
// 将横幅广告定位在屏幕底部60像素处
anchorOffset: 0.0,
// 将横幅广告定位在屏幕中心右侧10像素处
horizontalCenterOffset: 0.0,
// 横幅广告位置
anchorType: AnchorType.bottom,
);
}
static showInterstitial() {
myInterstitial
..load()
..show(
anchorType: AnchorType.bottom,
anchorOffset: 0.0,
horizontalCenterOffset: 0.0,
);
}
}
final Ads ads = Ads();
要显示它,我执行: Ads.showInterstitial();
但它从未显示。
如果我尝试再次调用它,错误会导致应用程序崩溃。
我在我的应用程序中不使用Statefull
小部件。
英文:
I'm using this package: https://pub.dev/packages/firebase_admob
Everything is setup correctly and the normal banner is showing. My problem comes only with the interstitial one:
import 'package:firebase_admob/firebase_admob.dart';
BannerAd myBanner = BannerAd(
adUnitId: BannerAd.testAdUnitId,
size: AdSize.smartBanner,
listener: (MobileAdEvent event) {
print("BannerAd event is $event");
},
);
InterstitialAd myInterstitial = InterstitialAd(
adUnitId: 'ca-app-pub-MYID',
listener: (MobileAdEvent event) {
print("InterstitialAd event is $event");
},
);
class Ads {
static showBanner() {
myBanner
// typically this happens well before the ad is shown
..load()
..show(
// Positions the banner ad 60 pixels from the bottom of the screen
anchorOffset: 0.0,
// Positions the banner ad 10 pixels from the center of the screen to the right
horizontalCenterOffset: 0.0,
// Banner Position
anchorType: AnchorType.bottom,
);
}
static showInterstitial() {
myInterstitial
..load()
..show(
anchorType: AnchorType.bottom,
anchorOffset: 0.0,
horizontalCenterOffset: 0.0,
);
}
}
final Ads ads = Ads();
To show it I do: Ads.showInterstitial();
but it's never shown.
If I try to call it again the error breaks the app.
I do not use Statefull
widgets on my app
答案1
得分: 1
我认为您需要将您设备的ID添加为testDevice,以便能够在那里看到广告。
添加一个targetingInfo属性,其中包含您设备的ID。
MobileAdTargetingInfo targetingInfo = MobileAdTargetingInfo(
testDevices:
);
并且在创建您的Interstitial字段时,添加targetingInfo属性,如插件页面的Readme中所述。
InterstitialAd myInterstitial = InterstitialAd(
// 用AdMob仪表板中的广告单元ID替换testAdUnitId。
// https://developers.google.com/admob/android/test-ads
// https://developers.google.com/admob/ios/test-ads
adUnitId: InterstitialAd.testAdUnitId,
targetingInfo: targetingInfo, // <--- 在这里
listener: (MobileAdEvent event) {
print("InterstitialAd事件为$event");
},
);
英文:
i think you have to add the ID of your device, as testDevice to be able to see the ads there.
add a targetingInfo property, where you add the ID of your device.
MobileAdTargetingInfo targetingInfo = MobileAdTargetingInfo(
testDevices: <String>["*add id of your device here*"], // Android emulators are considered test devices
);
and when creating your Interstitial field, add the targetingInfo property, like mentioned in the Readme of the plugin page.
InterstitialAd myInterstitial = InterstitialAd(
// Replace the testAdUnitId with an ad unit id from the AdMob dash.
// https://developers.google.com/admob/android/test-ads
// https://developers.google.com/admob/ios/test-ads
adUnitId: InterstitialAd.testAdUnitId,
targetingInfo: targetingInfo, // <--- here
listener: (MobileAdEvent event) {
print("InterstitialAd event is $event");
},
);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论