首页 > 解决方案 > Flutter ADS:为什么插页式广告在测试模式下有效,但在 Play Market 中无效?

问题描述

在 Interstitials 的测试模式下一切正常,但是当我在 play market 中加载捆绑包时,广告不起作用。添加了广告块。

编码:

class AdmobHelper {      
  InterstitialAd _interstitialAd;
  int num_of_attempt_load = 0;
  static initialization() {
    if (MobileAds.instance == null) {
      MobileAds.instance.initialize();
    }
  }
  void createInterad() {
    InterstitialAd.load(
      adUnitId: 'ca-app-pub-XXXXXXXXXXXXXXXX/XXXXXXXXXX',
      request: AdRequest(),
      adLoadCallback:
          InterstitialAdLoadCallback(onAdLoaded: (InterstitialAd ad) {
        _interstitialAd = ad;
        num_of_attempt_load = 0;
      }, onAdFailedToLoad: (LoadAdError error) {
        print('InterstitialAs FAILED to LOAD:---------- $error');
        // ignore: unnecessary_statements
        num_of_attempt_load + 1;
        _interstitialAd = null;

        if (num_of_attempt_load <= 2) {
          createInterad();
        }
      }),
    );
  }
  void showInterad() {
    if (_interstitialAd == null) {
      return;
    }
    _interstitialAd.fullScreenContentCallback = FullScreenContentCallback(
        onAdShowedFullScreenContent: (InterstitialAd ad) {
      print("ad onAdshowedFullscreen");
    }, onAdDismissedFullScreenContent: (InterstitialAd ad) {
      print("ad Disposed");
      ad.dispose();
    }, onAdFailedToShowFullScreenContent: (InterstitialAd ad, AdError aderror) {
      print("$ad OnAFAILED $aderror");
      ad.dispose();
      createInterad();
    });
    _interstitialAd.show();
    _interstitialAd = null;
  }
}

将标签添加到 AndoidManifest.xml

   <meta-data
       android:name="com.google.android.gms.ads.APPLICATION_ID"
       android:value="ca-app-pub-XXXXXXXXXXXXXX~XXXXXXXXX"/>

按钮本身调用广告
在测试模式下,按下按钮后,会打开一个测试广告

 onTap: () async {
    admobHelper.createInterad();
    admobHelper.showInterad();

    Navigator.push(
        context,
        new MaterialPageRoute(
            builder: (context) => EpgChannelList(
                filteredUsers[index],
                filteredUsers[index])));
  },
  onLongPress: (){
    admobHelper.createInterad();
    admobHelper.showInterad();
    Navigator.push(
        context,
        new MaterialPageRoute(
            builder: (context) => EpgChannelList(
                filteredUsers[index],
                filteredUsers[index])));
  },

标签: flutterdartadmob

解决方案


推荐阅读