Flutter、Admob、横幅广告尺寸(宽度:320,高度:50)不起作用

问题描述 投票:0回答:2
_bannerAd = BannerAd(
        size: AdSize.banner,
       ............

这完全运作良好,但是

 _bannerAd = BannerAd(
        size: AdSize(width:320, height: 50),
      .............

它根本不适用于下面

error failed code : 3

我的包裹是

google_mobile_ads: 0.11.0+4

最后小部件代码如下

Container(
     height: _bannerAd.size.height.toDouble(),
     width: _bannerAd.size.width.toDouble(),
      child: AdWidget(ad: _bannerAd))
flutter admob
2个回答
1
投票

你的问题不太具体。但是根据您的错误代码,这似乎与您的 AdSize 无关。 Google Play 参考资料显示广告请求成功,但由于广告库存不足而没有返回任何广告。

https://developers.google.com/android/reference/com/google/android/gms/ads/AdRequest#ERROR_CODE_NO_FILL


0
投票

我正在使用 google_mobile_ads:^5.1.0,通过此软件包版本,我可以显示具有自定义尺寸的 BannerAd。

下面是如何使用它的示例

 BannerAd? bannerAd;

   bannerAd = BannerAd(
          size: AdSize(width: 320, height: 50),
          adUnitId: bannerAdUnitId,
          request: const AdRequest(),
          listener: BannerAdListener(
            // Called when an ad is successfully received.
            onAdLoaded: (ad) {
              print("adLoaded ${ad.adUnitId}");
            },
            // Called when an ad request failed.
            onAdFailedToLoad: (ad, err) {
              print("onAdFailedToLoad$err");
              ad.dispose();
            },
            // Called when an ad opens an overlay that covers the screen.
            onAdOpened: (Ad ad) {
              print("onAdOpened$ad");
            },
            // Called when an ad removes an overlay that covers the screen.
            onAdClosed: (Ad ad) {
              print("onAdClosed$ad");
            },
            // Called when an impression occurs on the ad.
            onAdImpression: (Ad ad) {
              print("onAdImpression$ad");
            },
          ),
        );
    
        bannerAd?.load();
© www.soinside.com 2019 - 2024. All rights reserved.