@overridevoidinitState(){super.initState();// Create a ConsentRequestParameters object.finalparams=ConsentRequestParameters();// Request an update to consent information on every app launch.ConsentInformation.instance.requestConsentInfoUpdate(params,()async{// Called when consent information is successfully updated.},(FormErrorerror){// Called when there's an error updating consent information.},);}
@overridevoidinitState(){super.initState();// Create a ConsentRequestParameters object.finalparams=ConsentRequestParameters();// Request an update to consent information on every app launch.ConsentInformation.instance.requestConsentInfoUpdate(params,()async{ConsentForm.loadAndShowConsentFormIfRequired((loadAndShowError){if(loadAndShowError!=null){// Consent gathering failed.}// Consent has been gathered.});},(FormErrorerror){// Handle the error.},);}
/// Helper variable to determine if the privacy options entry point is required.Future<bool>isPrivacyOptionsRequired()async{returnawaitConsentInformation.instance.getPrivacyOptionsRequirementStatus()==PrivacyOptionsRequirementStatus.required;}
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-05 (世界標準時間)。"],[[["\u003cp\u003eThe Google User Messaging Platform (UMP) SDK helps manage user privacy choices and display relevant privacy messages within your app.\u003c/p\u003e\n"],["\u003cp\u003eYou need to add your Ad Manager application ID to your app and request consent information at each app launch using the UMP SDK.\u003c/p\u003e\n"],["\u003cp\u003eThe SDK provides ways to load and present privacy messages, handle privacy options, and check if you have consent to request ads.\u003c/p\u003e\n"],["\u003cp\u003eFor testing, you can programmatically register test devices and simulate different geographies to ensure proper functionality.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003ereset()\u003c/code\u003e method can be used for testing purposes to simulate a fresh install and reset the SDK's consent state.\u003c/p\u003e\n"]]],["The Google UMP SDK manages user privacy choices. Key actions include: creating message types in Ad Manager, updating consent info with `requestConsentInfoUpdate()` on app launch, and loading/presenting privacy forms via `loadAndShowConsentFormIfRequired()`. Apps must check if a privacy options entry point is required using `getPrivacyOptionsRequirementStatus()`. Before requesting ads, `canRequestAds()` checks user consent. The SDK allows testing with debug settings, forcing geography, and resetting consent state with `reset()`.\n"],null,["Select platform: [Android](/ad-manager/mobile-ads-sdk/android/privacy \"View this page for the Android platform docs.\") [iOS](/ad-manager/mobile-ads-sdk/ios/privacy \"View this page for the iOS platform docs.\") [Unity](/ad-manager/mobile-ads-sdk/unity/privacy \"View this page for the Unity platform docs.\") [Flutter](/ad-manager/mobile-ads-sdk/flutter/privacy \"View this page for the Flutter platform docs.\")\n\n\u003cbr /\u003e\n\nThe Google User Messaging Platform (UMP) SDK is a privacy and messaging tool to\nhelp you manage privacy choices. For more information, see\n\n[About Privacy \\& messaging](https://support.google.com/admanager/answer/10075997).\n\n\nCreate a message type\n\nCreate user messages with one of the\n\n[Available user message types](//support.google.com/admanager/answer/10075998)\n\nunder the **Privacy \\& messaging** tab of your\n\nAd Manager\n\naccount. The UMP SDK attempts to display a\nprivacy message created from the Ad Manager Application ID\nset in your project.\n\nFor more details, see\n\n[About privacy and messaging](//support.google.com/admanager/answer/10075997).\n\nGet the user's consent information\n\nYou should request an update of the user's consent information at every app\nlaunch, using `requestConsentInfoUpdate()`. This request checks the following:\n\n- **Whether consent is required**. For example, consent is required for the first time, or the previous consent decision expired.\n- **Whether a privacy options entry point is required**. Some privacy messages require apps to allow users to modify their privacy options at any time.\n\n @override\n void initState() {\n super.initState();\n\n // Create a ConsentRequestParameters object.\n final params = ConsentRequestParameters();\n\n // Request an update to consent information on every app launch.\n ConsentInformation.instance.requestConsentInfoUpdate(\n params,\n () async {\n // Called when consent information is successfully updated.\n },\n (FormError error) {\n // Called when there's an error updating consent information.\n },\n );\n }\n\n| **Warning:** Using other ways of checking consent status, such as the cache on your app or a previously saved consent string, can lead to a [TCF 3.3 error](//support.google.com/admanager/answer/9999955) if consent is expired.\n\nLoad and present the privacy message form\n\nAfter you have received the most up-to-date consent status, call\n`loadAndShowConsentFormIfRequired()` to load any forms required to\ncollect user consent. After loading, the forms present immediately.\n**Key Point:** If no privacy message forms require collection of user consent prior to requesting ads, the callback is invoked immediately. \n\n @override\n void initState() {\n super.initState();\n\n // Create a ConsentRequestParameters object.\n final params = ConsentRequestParameters();\n\n // Request an update to consent information on every app launch.\n ConsentInformation.instance.requestConsentInfoUpdate(\n params,\n () async {\n ConsentForm.loadAndShowConsentFormIfRequired((loadAndShowError) {\n if (loadAndShowError != null) {\n // Consent gathering failed.\n }\n\n // Consent has been gathered.\n });\n },\n (FormError error) {\n // Handle the error.\n },\n );\n }\n\nPrivacy options\n\nSome privacy message forms are presented from a publisher-rendered privacy\noptions entry point, letting users manage their privacy options at any time.\nTo learn more about which message your users see at the privacy options\nentry point, see\n\n[Available user message types](//support.google.com/admanager/answer/10075998).\n\n\nCheck if a privacy options entry point is required\n\nAfter you have called `requestConsentInfoUpdate()`, check `getPrivacyOptionsRequirementStatus()` to\ndetermine if a privacy options entry point is required for your app. If an entry\npoint is required, add a visible and interactable UI element to your app that\npresents the privacy options form. If a privacy entry point is not required,\nconfigure your UI element to be not visible and interactable. \n\n /// Helper variable to determine if the privacy options entry point is required.\n Future\u003cbool\u003e isPrivacyOptionsRequired() async {\n return await ConsentInformation.instance\n .getPrivacyOptionsRequirementStatus() ==\n PrivacyOptionsRequirementStatus.required;\n }\n\nFor the full list of privacy options requirement statuses, see\n`\n`[`PrivacyOptionsRequirementStatus`](//pub.dev/documentation/google_mobile_ads/latest/google_mobile_ads/PrivacyOptionsRequirementStatus.html).\n\nPresent the privacy options form\n\nWhen the user interacts with your element, present the privacy options form: \n\n ConsentForm.showPrivacyOptionsForm((formError) {\n if (formError != null) {\n debugPrint(\"${formError.errorCode}: ${formError.message}\");\n }\n });\n\nRequest ads with user consent\n\nBefore requesting ads, use `canRequestAds()` to check if you've\nobtained consent from the user: \n\n await ConsentInformation.instance.canRequestAds()\n\nListed are the following places to check if you can request ads while gathering\nconsent:\n\n- After the UMP SDK gathers consent in the current session.\n- Immediately after you have called `requestConsentInfoUpdate()`. The UMP SDK might have obtained consent in the previous app session.\n\n| **Important:** `canRequestAds()` always returns `false` until you have called `requestConsentInfoUpdate()`\n\nIf an error occurs during the consent gathering process, check if you can\nrequest ads. The UMP SDK uses the consent status from the previous app session.\n\nPrevent redundant ad request work\n\nAs you check `canRequestAds()` after gathering consent and after calling\n`requestConsentInfoUpdate()`, ensure your logic prevents redundant ad requests that\nmight result in both checks returning `true`. For example, with a boolean\nvariable.\n\n\u003cbr /\u003e\n\nTesting\n\nIf you want to test the integration in your app as you're developing, follow\nthese steps to programmatically register your test device. Be sure to remove the\ncode that sets these test device IDs before you release your app.\n\n1. Call `requestConsentInfoUpdate()`.\n2. Check the log output for a message similar to the following example, which\n shows your device ID and how to add it as a test device:\n\n Android \n\n Use new ConsentDebugSettings.Builder().addTestDeviceHashedId(\"33BE2250B43518CCDA7DE426D04EE231\")\n to set this as a debug device.\n\n iOS \n\n \u003cUMP SDK\u003eTo enable debug mode for this device,\n set: UMPDebugSettings.testDeviceIdentifiers = @[2077ef9a63d2b398840261c8221a0c9b]\n\n3. Copy your test device ID to your clipboard.\n\n4. Modify your code to call\n `ConsentDebugSettings.testIdentifiers` and pass in\n a list of your test device IDs.\n\n ConsentDebugSettings debugSettings = ConsentDebugSettings(\n testIdentifiers: [\"TEST-DEVICE-HASHED-ID\"],\n );\n\n ConsentRequestParameters params =\n ConsentRequestParameters(consentDebugSettings: debugSettings);\n\n ConsentInformation.instance.requestConsentInfoUpdate(params, () async {\n // ...\n };\n\nForce a geography\n\nThe UMP SDK provides a way to test your app's behavior as though the device\nwere located in various regions, such as the EEA or UK, using\n\n`debugGeography`. Note that debug settings only work on test devices. \n\n ConsentDebugSettings debugSettings = ConsentDebugSettings(\n debugGeography: DebugGeography.debugGeographyEea,\n testIdentifiers: [\"TEST-DEVICE-HASHED-ID\"],\n );\n\n ConsentRequestParameters params =\n ConsentRequestParameters(consentDebugSettings: debugSettings);\n\n ConsentInformation.instance.requestConsentInfoUpdate(params, () async {\n // ...\n };\n\nReset consent state\n\nWhen testing your app with the UMP SDK, you might find it helpful to reset the\nstate of the SDK so that you can simulate a user's first install experience.\nThe SDK provides the `reset()` method to do this. \n\n ConsentInformation.instance.reset();\n\n| **Caution:** This method is intended to be used for testing purposes only. You shouldn't call `reset()` in production code.\n\nExamples on GitHub\n\nSee a full example of the UMP SDK integration covered in this page in\n\n[our Flutter examples](//github.com/googleads/googleads-mobile-flutter/tree/main/samples/admob)."]]