I'm trying to obtain the consent from the users using User Messaging Platform. Followed this guide:
https://developers.google.com/admob/ump/android/quick-start
When I run the code in the guide it shows the consent correctly. If I press "Consent" the consent status changes to ConsentInformation.ConsentStatus.OBTAINED
which is ok.
But when I kill and re-open the app again, after calling requestConsentInfoUpdate, it seems to reset the consent status to ConsentInformation.ConsentStatus.REQUIRED
and prompts again for consent.
How can I avoid that and only prompt once for consent?
First make sure you are using the latest version of UMP SDK inside your dependencies and don't rely on the version embedded with
play-services-ads
, that version could be outdated.Second, in my case Android DataStore was causing preferences reset. The same preferences file is used to store consent from UMP SDK, coincidently they had the same name. It seems that DataStore tries to migrate all preferences when it finds the preferences file, and then deletes it, which causes UMP SDK to lose stored consent info.
UMP SDK uses
my.package.name_preferences.xml
file by default (can't change it) to store consent info. My old preferences also were stored in the same file, and when I switched to DataStore I had to make a migration from that file.To resolve the issue, I simply removed the migration since it is not that important for me.