快速入門指南說明如何初始化 Google Mobile Ads 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,["上次更新時間:2025-09-02 (世界標準時間)。"],[[["\u003cp\u003eThis guide explains how to integrate mediation adapters, allowing you to display ads from multiple ad networks within your Flutter app to maximize revenue.\u003c/p\u003e\n"],["\u003cp\u003eBefore integrating mediation, you must integrate the desired ad formats (banner, interstitial, native, rewarded, rewarded interstitial) into your app and initialize the Mobile Ads SDK.\u003c/p\u003e\n"],["\u003cp\u003eYou need to add the necessary dependencies for your chosen partner ad networks to your Android and iOS projects, updating your \u003ccode\u003ebuild.gradle\u003c/code\u003e and \u003ccode\u003ePodfile\u003c/code\u003e accordingly.\u003c/p\u003e\n"],["\u003cp\u003eFor banner ads used in mediation, disable refresh in third-party ad source UIs to prevent double refreshes, and for native ads, ensure your app complies with each ad network's policies and relevant privacy regulations.\u003c/p\u003e\n"]]],["To integrate mediation with a Flutter app, first initialize the Mobile Ads SDK, ensuring all mediation adapters are initialized before loading ads. Update the `settings.gradle` file (Android) and add dependencies for partner networks in `build.gradle` (Android) and `Podfile` (iOS). Check adapter initialization status and log the ad network class name upon ad load. Disable refresh in third-party ad UIs for banner ads. Finally, comply with U.S. states privacy laws or GDPR by adding mediation partners to the relevant lists in Ad Manager Privacy & messaging.\n"],null,["\u003cbr /\u003e\n\nThis guide shows you how to integrate a mediation adapter with your\nFlutter app.\n\nPrerequisites\n\nBefore you can integrate mediation for an ad format, you need to integrate that\nad format into your app:\n\n- [Banner Ads](/ad-manager/mobile-ads-sdk/flutter/banner)\n- [Interstitial Ads](/ad-manager/mobile-ads-sdk/flutter/interstitial)\n- [Native Ads](/ad-manager/mobile-ads-sdk/flutter/native)\n- [Rewarded Ads](/ad-manager/mobile-ads-sdk/flutter/rewarded)\n- [Rewarded Interstitial\n Ads](/ad-manager/mobile-ads-sdk/flutter/rewarded-interstitial)\n\nNew to mediation? Read\n\n[Introduction to mediation](//support.google.com/admanager/answer/6272813).\n\nInitialize Google Mobile Ads SDK\n\nThe quick start guide shows you how to [initialize the Google Mobile Ads SDK](/ad-manager/mobile-ads-sdk/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\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\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](/ad-manager/mobile-ads-sdk/android/choose-networks#network_details)\nand\n[iOS](/ad-manager/mobile-ads-sdk/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\nThe following sample code demonstrates how to log the ad network class name for\na banner ad: \n\n final bannerAd = AdManagerBannerAd(\n size: [AdSize.banner],\n adUnitId: '\u003cyour-ad-unit\u003e',\n listener: AdManagerBannerAdListener(\n onAdLoaded: (ad) {\n debugPrint('$ad loaded: ${ad.responseInfo?.mediationAdapterClassName}');\n },\n ),\n request: AdManagerAdRequest(),\n );\n\nUse banner ads with mediation\n\nMake sure to disable refresh in all third-party ad source UIs for banner ad\nunits used in mediation. This prevents a\ndouble refresh since Ad Manager also triggers a refresh\nbased on your banner ad unit's refresh rate.\n\nUse native ads with mediation\n\nThe following are some best practices to consider when implementing native\nmediation.\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\nIf you need to comply with the [U.S. states privacy\nlaws](//support.google.com/admanager/answer/9561023) or [General Data Protection\nRegulation (GDPR)](//support.google.com/admanager/answer/7666366), follow the\nsteps in [US state regulations\nsettings](//support.google.com/admanager/answer/10115735) or [GDPR\nsettings](//support.google.com/admanager/answer/10113006#adding_ad_partners_to_published_gdpr_messages) to add your\nmediation partners in Ad Manager 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)](/ad-manager/mobile-ads-sdk/flutter/privacy/us-states) and obtaining GDPR consent with the\n[Google User Messaging Platform (UMP) SDK](/ad-manager/mobile-ads-sdk/flutter/privacy)."]]