User Messaging Platform for Android misses the user consent status

657 views Asked by At

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?

1

There are 1 answers

0
hiddeneyes02 On

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.

dependencies {
   implementation("com.google.android.gms:play-services-ads:22.6.0")
   implementation("com.google.android.ump:user-messaging-platform:2.2.0")
}

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.

companion object {

    private const val PREFS_FILE_NAME = "user_prefs"
    private val Context.dataStore by preferencesDataStore(
        name = PREFS_FILE_NAME,
        produceMigrations = {
            listOf(SharedPreferencesMigration(it, it.packageName + "_preferences"))
        })
}

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.