本快速入门指南介绍了如何初始化 Google 移动广告 SDK。在初始化调用期间,中介适配器也会初始化。请务必在初始化完成后再加载广告,以验证每个广告联盟是否都可完全参与第一个广告请求。
以下示例代码展示了如何在发出广告请求前检查每个适配器的初始化状态。
voidmain(){WidgetsFlutterBinding.ensureInitialized();MobileAds.instance.initialize().then((initializationStatus){initializationStatus.adapterStatuses.forEach((key,value){debugPrint('Adapter status for $key: ${value.description}');});});runApp(MyApp());}
defflutterSdkPath={defproperties=newProperties()file("local.properties").withInputStream{properties.load(it)}defflutterSdkPath=properties.getProperty("flutter.sdk")assertflutterSdkPath!=null,"flutter.sdk not set in local.properties"returnflutterSdkPath}()includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")
[null,null,["最后更新时间 (UTC):2025-08-31。"],[[["\u003cp\u003eAdMob Mediation lets you maximize ad revenue by serving ads from multiple ad networks, including AdMob and third-party sources, all in one platform.\u003c/p\u003e\n"],["\u003cp\u003eBefore integrating mediation, ensure you've integrated the desired ad format (banner, interstitial, native, rewarded, or rewarded interstitial) and initialized the Mobile Ads SDK.\u003c/p\u003e\n"],["\u003cp\u003eYou'll need to add dependencies for your chosen partner networks in your Android and iOS projects and update your Gradle settings for Android.\u003c/p\u003e\n"],["\u003cp\u003eAdMob Mediation requires specific configurations for banner and native ads to ensure optimal performance and compliance with ad network policies.\u003c/p\u003e\n"],["\u003cp\u003eTo comply with privacy regulations like GDPR and U.S. state privacy laws, remember to add your mediation partners to the AdMob Privacy & messaging settings.\u003c/p\u003e\n"]]],["AdMob Mediation serves ads from multiple sources, maximizing fill rates. Key actions include: verifying account permissions, integrating ad formats (banner, interstitial, native, rewarded), and initializing the Mobile Ads SDK while checking adapter statuses. Update Android's `settings.gradle` and add dependencies for partner networks via `build.gradle` (Android) or `Podfile` (iOS). Disable refresh on third-party UIs for banner ads. Adhere to ad network policies and ensure partners are listed for US states' privacy laws and GDPR compliance.\n"],null,["# Mediation\n\nAdMob Mediation is a feature lets you serve ads to your apps from\nmultiple sources, including the AdMob Network and third-party ad sources, in\none place. AdMob Mediation helps maximize your fill rate and increase your\nmonetization by sending ad requests to multiple networks to verify you find the\nbest available network to serve ads.\n[Case study](//admob.google.com/home/resources/cookapps-grows-ad-revenue-86-times-with-admob-rewarded-ads-and-mediation/).\n\n\nPrerequisites\n-------------\n\n| **Important:** Verify that you have the necessary account permissions to complete the mediation configuration. These permissions include access to inventory management, app access, and privacy and messaging features. See [Manage user access to your\n| account](//support.google.com/admob/answer/2784628) for details.\n\nBefore you can integrate mediation for an ad format, you need to integrate that\nad format into your app:\n\n- [Banner Ads](/admob/flutter/banner)\n- [Interstitial Ads](/admob/flutter/interstitial)\n- [Native Ads](/admob/flutter/native)\n- [Rewarded Ads](/admob/flutter/rewarded)\n- [Rewarded Interstitial\n Ads](/admob/flutter/rewarded-interstitial)\n\nNew to mediation? Read\n\n[Overview of AdMob Mediation](//support.google.com/admob/answer/3063564).\n\nInitialize\nGoogle Mobile Ads SDK\n--------------------------------\n\nThe quick start guide shows you how to [initialize the\nGoogle Mobile Ads SDK](/admob/flutter/quick-start#initialize_the_mobile_ads_sdk).\nDuring that initialization call, mediation adapters also\nget initialized. It is important to wait for initialization to complete before\nyou load ads in order to verify full participation from every ad network on the\nfirst ad request.\n| **Important:** Bidding adapters require you to explicitly initialize Google Mobile Ads SDK .\n\nThe following sample code shows how you can check each adapter's initialization\nstatus prior to making an ad request. \n\n void main() {\n WidgetsFlutterBinding.ensureInitialized();\n MobileAds.instance.initialize()\n .then((initializationStatus) {\n initializationStatus.adapterStatuses.forEach((key, value) {\n debugPrint('Adapter status for $key: ${value.description}');\n });\n });\n runApp(MyApp());\n }\n\nUpdate your gradle settings (Android only)\n------------------------------------------\n\nAdd the following lines to your `settings.gradle` file, so you can use the\nplugin's Android APIs: \n\n def flutterSdkPath = {\n def properties = new Properties()\n file(\"local.properties\").withInputStream { properties.load(it) }\n def flutterSdkPath = properties.getProperty(\"flutter.sdk\")\n assert flutterSdkPath != null, \"flutter.sdk not set in local.properties\"\n return flutterSdkPath\n }()\n\n includeBuild(\"$flutterSdkPath/packages/flutter_tools/gradle\")\n\nAdd dependencies for partner networks\n-------------------------------------\n\nThe mediation adapters and their dependencies need to be added to your Android\nand iOS projects. They can be added by updating your app level `build.gradle`\nfile on Android and `Podfile` on iOS. Google has open source adapters in GitHub\nfor both\n[Android](//github.com/googleads/googleads-mobile-android-mediation/tree/master/ThirdPartyAdapters)\nand\n[iOS](//github.com/googleads/googleads-mobile-ios-mediation/tree/main/adapters).\n\nSee the\n[Android](/admob/android/choose-networks#network_details)\nand\n[iOS](/admob/ios/choose-networks#network_details)\ndocumentation for each partner network for detailed guidance of how to add their\nadapter in your app.\n\nCheck which ad network adapter class loaded the ad\n--------------------------------------------------\n\nThe following sample code demonstrates how to log the ad network class name for\na banner ad: \n\n final bannerAd = BannerAd(\n size: AdSize.banner,\n adUnitId: '\u003cyour-ad-unit\u003e',\n listener: BannerAdListener(\n onAdLoaded: (ad) {\n debugPrint('$ad loaded: ${ad.responseInfo?.mediationAdapterClassName}');\n },\n ),\n request: AdRequest(),\n );\n\nUse banner ads with AdMob Mediation\n-----------------------------------\n\nMake sure to disable refresh in all third-party ad source UIs for banner ad\nunits used in AdMob Mediation. This prevents a double refresh since\nAdMob also triggers a refresh based on your banner ad unit's\nrefresh rate.\n\nUse native ads with AdMob Mediation\n-----------------------------------\n\nThe following are some best practices to consider when implementing native ads\nin AdMob Mediation.\n\nNative ad presentation policy\n: Each ad network has its own policies. When using mediation, it's important to\n remember that your app still needs to abide by the policies of the mediated\n network that provided the ad.\n\nUS states privacy laws and GDPR\n-------------------------------\n\nIf you need to comply with the [U.S. states privacy\nlaws](//support.google.com/admob/answer/9561022) or [General Data Protection\nRegulation (GDPR)](//support.google.com/admob/answer/7666366), follow the\nsteps in [US state regulations\nsettings](//support.google.com/admob/answer/10860309) or [GDPR\nsettings](//support.google.com/admob/answer/10113004#adding_ad_partners_to_published_gdpr_messages) to add your\nmediation partners in AdMob Privacy \\& messaging's\nUS states or GDPR ad partners list. Failure to do so can lead to partners\nfailing to serve ads on your app.\n\nLearn more about enabling [restricted data processing\n(RDP)](/admob/flutter/privacy/us-states) and obtaining GDPR consent with the\n[Google User Messaging Platform (UMP) SDK](/admob/flutter/privacy)."]]