Created
October 31, 2023 12:04
-
-
Save winnerawan/197dcb94df3e47634cd59de41d6137ca to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * GDPR | |
| */ | |
| private lateinit var consentInformation: ConsentInformation | |
| private lateinit var consentForm: ConsentForm | |
| private fun requestConsentInfoUpdate() { | |
| val debugSettings = ConsentDebugSettings.Builder(this) | |
| .setDebugGeography(ConsentDebugSettings.DebugGeography.DEBUG_GEOGRAPHY_EEA) | |
| .addTestDeviceHashedId("031D13417E3C53BD3857B9DD326A6154") | |
| .build() | |
| // Set tag for under age of consent. false means users are not under | |
| // age. | |
| val params = ConsentRequestParameters | |
| .Builder() | |
| .setConsentDebugSettings(debugSettings) | |
| .setTagForUnderAgeOfConsent(false) | |
| .build() | |
| consentInformation = UserMessagingPlatform.getConsentInformation(this) | |
| consentInformation.requestConsentInfoUpdate( | |
| this, | |
| params, | |
| { | |
| // The consent information state was updated. | |
| // You are now ready to check if a form is available. | |
| if (consentInformation.isConsentFormAvailable) { | |
| loadForm() | |
| } | |
| }, | |
| { | |
| // Handle the error. | |
| Log.e("LOG", "ERROR REQ CONSENT: ${it.message}") | |
| }) | |
| } | |
| private fun loadForm() { | |
| // Loads a consent form. Must be called on the main thread. | |
| UserMessagingPlatform.loadConsentForm( | |
| this, | |
| { | |
| this.consentForm = it | |
| if (consentInformation.consentStatus == ConsentInformation.ConsentStatus.REQUIRED) { | |
| consentForm.show( | |
| this, | |
| ConsentForm.OnConsentFormDismissedListener { | |
| if (consentInformation.consentStatus == ConsentInformation.ConsentStatus.OBTAINED) { | |
| // App can start requesting ads. | |
| } | |
| // Handle dismissal by reloading form. | |
| loadForm() | |
| } | |
| ) | |
| } | |
| }, | |
| { | |
| // Handle the error. | |
| Log.e("LOG", "ERROR CONSENT: ${it.message}") | |
| } | |
| ) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment