插页式广告
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
插页式广告是全屏广告,会覆盖所在应用的整个界面。这些广告通常会在应用流程的自然过渡点(例如活动之间的切换处或游戏关卡之间的暂停时段)展示。当应用展示插页式广告时,用户既可以选择点按该广告,进而访问其目标网址,也可以将其关闭,并返回应用。
本指南介绍了如何将插页式广告植入到 Flutter 应用中。
务必用测试广告进行测试
在构建和测试应用时,请确保使用的是测试广告,而不是实际投放的广告。否则,可能会导致您的账号被暂停。
对于插页式广告,加载测试广告最简便的方法就是使用我们的专用测试广告单元 ID:
/21775744923/example/interstitial
这些 ID 已经过专门配置,可针对每个请求返回测试广告。您可以在编码、测试和调试期间,在自己的应用中随意使用这些 ID。只是一定要在发布应用前用您自己的广告单元 ID 替换这些测试广告单元 ID。
加载广告
以下示例会加载一个插页式广告:
将 _adUnitId 替换为您自己的广告单元 ID。
插页式广告事件
通过使用 FullScreenContentCallback
,您可以监听各种广告生命周期事件,例如广告何时展示或何时关闭。请在展示广告之前设置 AdManagerInterstitialAd.fullScreenContentCallback
,以便接收关于这些事件的通知。以下示例实现了每个方法:
ad.fullScreenContentCallback = FullScreenContentCallback(
onAdShowedFullScreenContent: (ad) {
// Called when the ad showed the full screen content.
debugPrint('Ad showed full screen content.');
},
onAdFailedToShowFullScreenContent: (ad, err) {
// Called when the ad failed to show full screen content.
debugPrint('Ad failed to show full screen content with error: $err');
// Dispose the ad here to free resources.
ad.dispose();
},
onAdDismissedFullScreenContent: (ad) {
// Called when the ad dismissed full screen content.
debugPrint('Ad was dismissed.');
// Dispose the ad here to free resources.
ad.dispose();
},
onAdImpression: (ad) {
// Called when an impression occurs on the ad.
debugPrint('Ad recorded an impression.');
},
onAdClicked: (ad) {
// Called when a click is recorded for an ad.
debugPrint('Ad was clicked.');
},
);
展示插页式广告
AdManagerInterstitialAd
会作为 Overlay
展示在所有应用内容之前,并以静态方式放置;因此,您无法将其添加到 Flutter widget 树中。您可以通过调用 show()
来选择广告展示时间。
_interstitialAd?.show();
调用 show()
后,以这种方式展示的 Ad
无法以编程方式关闭,并且需要用户输入内容。AdManagerInterstitialAd
仅可展示一次。后续的展示调用将触发 onAdFailedToShowFullScreenContent
。
如果不再需要访问广告,必须对其进行处置。关于何时调用 dispose()
,最佳做法是在 FullScreenContentCallback.onAdDismissedFullScreenContent
和 FullScreenContentCallback.onAdFailedToShowFullScreenContent
回调函数中调用。
大功告成!您的应用现在就可以展示插页式广告了。
后续步骤
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-25。
[null,null,["最后更新时间 (UTC):2025-08-25。"],[[["\u003cp\u003eInterstitial ads are full-screen ads displayed at natural transition points in an app, giving users the choice to interact or close them.\u003c/p\u003e\n"],["\u003cp\u003eAlways test with test ads during development to avoid account suspension, using the provided test ad unit ID \u003ccode\u003e/21775744923/example/interstitial\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eLoad an interstitial ad using \u003ccode\u003eAdManagerInterstitialAd.load()\u003c/code\u003e and handle ad events with \u003ccode\u003eFullScreenContentCallback\u003c/code\u003e for lifecycle management.\u003c/p\u003e\n"],["\u003cp\u003eDisplay the ad using \u003ccode\u003e_interstitialAd.show()\u003c/code\u003e, noting it cannot be programmatically dismissed and should be disposed of properly after display.\u003c/p\u003e\n"]]],[],null,["# Interstitial\n\nSelect platform: [Android](/ad-manager/mobile-ads-sdk/android/interstitial \"View this page for the Android platform docs.\") [iOS](/ad-manager/mobile-ads-sdk/ios/interstitial \"View this page for the iOS platform docs.\") [Unity](/ad-manager/mobile-ads-sdk/unity/interstitial \"View this page for the Unity platform docs.\") [Flutter](/ad-manager/mobile-ads-sdk/flutter/interstitial \"View this page for the Flutter platform docs.\")\n\n\u003cbr /\u003e\n\nInterstitial ads are full-screen ads that cover the interface of their host app.\nThey're typically displayed at natural transition points in the flow of an app,\nsuch as between activities or during the pause between levels in a game. When an\napp shows an interstitial ad, the user has the choice to either tap on the ad\nand continue to its destination or close it and return to the app.\n\nThis guide explains how to integrate interstitial ads into a Flutter app.\n\nAlways test with test ads\n-------------------------\n\nWhen building and testing your apps, make sure you use test ads rather than\nlive, production ads. Failure to do so can lead to suspension of your account.\n\nThe easiest way to load test ads is to use our dedicated test ad unit ID for\ninterstitials:\n\n- `/21775744923/example/interstitial`\n\nThe test ad units are configured to return test ads for every request, and\nyou're free to use them in your own apps while coding, testing, and debugging.\nJust make sure you replace them with your own ad unit IDs before publishing your\napp.\n\n### Load an ad\n\nThe following example loads an interstitial ad: \n\n InterstitialAd.load(\n adUnitId: \"\u003cvar translate=\"no\"\u003e_adUnitId\u003c/var\u003e\",\n request: const AdManagerAdRequest(),\n adLoadCallback: InterstitialAdLoadCallback(\n onAdLoaded: (InterstitialAd ad) {\n // Called when an ad is successfully received.\n debugPrint('Ad was loaded.');\n // Keep a reference to the ad so you can show it later.\n _interstitialAd = ad;\n },\n onAdFailedToLoad: (LoadAdError error) {\n // Called when an ad request failed.\n debugPrint('Ad failed to load with error: $error');\n },\n ),\n ); \n https://github.com/googleads/googleads-mobile-flutter/blob/5dce0f8f948d1fd04a5e156d80ed0ea6e17f837c/packages/google_mobile_ads/example/lib/snippets/interstitial_ad_snippets.dart#L91-L109\n\nReplace \u003cvar translate=\"no\"\u003e_adUnitId\u003c/var\u003e with your own ad unit ID.\n\n### Interstitial ad events\n\nThrough the use of `FullScreenContentCallback`, you can listen for lifecycle\nevents, such as when the ad is shown or dismissed. Set\n`AdManagerInterstitialAd.fullScreenContentCallback` before showing the ad to receive\nnotifications for these events. This example implements each method: \n\n ad.fullScreenContentCallback = FullScreenContentCallback(\n onAdShowedFullScreenContent: (ad) {\n // Called when the ad showed the full screen content.\n debugPrint('Ad showed full screen content.');\n },\n onAdFailedToShowFullScreenContent: (ad, err) {\n // Called when the ad failed to show full screen content.\n debugPrint('Ad failed to show full screen content with error: $err');\n // Dispose the ad here to free resources.\n ad.dispose();\n },\n onAdDismissedFullScreenContent: (ad) {\n // Called when the ad dismissed full screen content.\n debugPrint('Ad was dismissed.');\n // Dispose the ad here to free resources.\n ad.dispose();\n },\n onAdImpression: (ad) {\n // Called when an impression occurs on the ad.\n debugPrint('Ad recorded an impression.');\n },\n onAdClicked: (ad) {\n // Called when a click is recorded for an ad.\n debugPrint('Ad was clicked.');\n },\n ); \n https://github.com/googleads/googleads-mobile-flutter/blob/5dce0f8f948d1fd04a5e156d80ed0ea6e17f837c/packages/google_mobile_ads/example/lib/snippets/interstitial_ad_snippets.dart#L56-L81\n\nDisplay an interstitial ad\n--------------------------\n\nAn `AdManagerInterstitialAd` is displayed as an [`Overlay`](//api.flutter.dev/flutter/widgets/Overlay-class.html)\non top of all app content and is statically placed; thus, it can't be added to\nthe Flutter widget tree. You can choose when to show the ad by calling `show()`. \n\n _interstitialAd?.show(); \n https://github.com/googleads/googleads-mobile-flutter/blob/5dce0f8f948d1fd04a5e156d80ed0ea6e17f837c/samples/admob/interstitial_example/lib/main.dart#L238-L238\n\nOnce `show()` is called, an `Ad` displayed this way can't be dismissed\nprogrammatically and requires user input. An `AdManagerInterstitialAd` can only be shown\nonce. Subsequent calls to show will trigger `onAdFailedToShowFullScreenContent`.\n\nAn ad must be disposed when access to it is no longer needed. The best practice\nfor when to call `dispose()` is in the\n`FullScreenContentCallback.onAdDismissedFullScreenContent` and\n`FullScreenContentCallback.onAdFailedToShowFullScreenContent` callbacks.\n\nThat's it! Your app is now ready to display interstitial ads.\n\nNext steps\n----------\n\n- See [Interstitial best\n practices](//www.youtube.com/watch?v=r2RgFD3Apyo&index=5&list=PLOU2XLYxmsIKX0pUJV3uqp6N3NeHwHh0c) and [interstitial ad guidance](//support.google.com/admob/answer/6066980).\n- Check out an [Interstitial ads case\n study](//admob.google.com/home/resources/freaking-math-powers-revenue-increase-with-google-admob-support/)."]]