Bug: ad-consent dialog stays even if on one Activity it was dismissed

135 views
Skip to first unread message

Liran Barsisa

unread,
Jan 24, 2024, 5:57:44 AM1/24/24
to Google Mobile Ads SDK Developers
Inside an app that I work on, we decided to have the official flow of showing ad-consent dialog when we detect that it's needed.

However, there is a scenario that its outcome doesn't make sense:

1. Ad-consent dialog is shown on Activity1. User goes to another app (can press Home button, for example)
2. User reaches Activity2, and the ad-consent dialog appears there now.
3. User chose to consent, leaves Activity2.
4. User switches to Activity1

The bug is that the ad-consent dialog is still being shown there.

Please either fix this or offer API to handle this use case.

gradle dependency is:

    implementation "com.google.android.ump:user-messaging-platform:2.1.0"

Liran Barsisa

unread,
Jan 24, 2024, 6:10:25 AM1/24/24
to Google Mobile Ads SDK Developers
The only callback we have is when the dialog is dismissed.
There is no callback for when it's shown, there is no API to dismiss the dialog on our own. 
Even showing it manually (using UserMessagingPlatform.showPrivacyOptionsForm) isn't guaranteed to always show it.

Mobile Ads SDK Forum Advisor

unread,
Jan 24, 2024, 6:47:24 AM1/24/24
to lbl...@gmail.com, google-adm...@googlegroups.com

Hi,

Thank you for contacting the Mobile Ads SDK Support team.

I will check with our team regarding your query and one of my team members will reach out to you once we have an update on this. Meanwhile, your patience is highly appreciated.

 
This message is in relation to case "ref:!00D1U01174p.!5004Q02rYOSm:ref"

Thanks,
 
Google Logo Mobile Ads SDK Team


عثمان عصومي

unread,
Jan 24, 2024, 11:04:07 AM1/24/24
to Liran Barsisa, Google Mobile Ads SDK Developers
--

---
You received this message because you are subscribed to the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-admob-ads...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-admob-ads-sdk/d97a3a75-301e-4346-bcc2-8aa21807a70cn%40googlegroups.com.

Mobile Ads SDK Forum Advisor

unread,
Jan 24, 2024, 11:43:14 AM1/24/24
to swmy...@gmail.com, google-adm...@googlegroups.com, lbl...@gmail.com

Hi, 

Thank you for contacting the Mobile Ads SDK Support team.

I see that you have already raised this concern on another thread with the subject ‘Bug: ad-consent dialog stays even if on one Activity it was dismissed’ and we have already responded to this issue. To avoid multiple threads on the same issue, please take a look at that thread and continue the discussion on the same for further updates on the issue.

 
This message is in relation to case "ref:!00D1U01174p.!5004Q02rYS5H:ref"


Thanks,
 
Google Logo Mobile Ads SDK Team


Liran Barsisa

unread,
Jan 24, 2024, 11:51:08 AM1/24/24
to Mobile Ads SDK Forum Advisor, swmy...@gmail.com, google-adm...@googlegroups.com
Where? Please share the 2 links that are duplicates.

Mobile Ads SDK Forum Advisor

unread,
Jan 26, 2024, 4:24:52 PM1/26/24
to lbl...@gmail.com, google-adm...@googlegroups.com
Hi Liran,

This sounds like a scenario outside of our typical use case. Can you provide a minimal sample demonstrating this issue?

Thanks,
Nick

ref:!00D1U01174p.!5004Q02rYOSm:ref
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted

Liran Barsisa

unread,
Jan 26, 2024, 7:24:46 PM1/26/24
to Google Mobile Ads SDK Developers
Why is it outside of your typical use case?
Apps on Android can be opened via various ways. 
Be it from the launcher, notification, widgets, other apps...
For each one you can even reach a different Activity.
Not to mention users who have upgraded the app so they reach a different flow than new users...

By "sample", do you want an APK, or a whole open sourced project ? 
I can't just give you something open sourced, because then it means it's easy to get my keys etc... no?
Or is it possible to show ad-consent without any key of any kind? Without even Admob account?

If you wish, it's quite easy to create the sample on your own:
1. Set up Admob account for the app.
2. Have 2 Activities that you can launch from the launcher (or one from launcher, and another from somewhere else, as I've mentioned), each with a different taskAffinity (to make sure you can switch between them via the recent-tasks). Example:

<activity
android:name=".MainActivity" android:exported="true" android:label="MainActivity"
android:taskAffinity="com.package.task_for_inventory_activity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:name=".MainActivity2" android:exported="true" android:label="MainActivity2"
android:taskAffinity="com.package.task_for_work_order_activity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

3. For each, follow the instructions of having the normal flow of ad-consent dialog to appear. As I can't demonstrate it without a real Admob account and key being used in the sample, I've used a simple dialog instead:

MaterialAlertDialogBuilder(this).setTitle(javaClass.simpleName).setMessage("TODO: replace this dialog with a normal official flow of ad-consent dialog").show()

4. Launch the app for first Activity. Press home button.
5.Launch the app for second Activity. Choose to accept all. In my sample, just dismiss the dialog.
6. Go back to the first Activity. You will still see the ad-consent dialog, as if you haven't chosen anything. In my sample, you will see the dialog of this Activity (makes sense, nothing has closed it).

Attached a skeleton sample, that you can "reproduce" the issue. I've created a normal dialog instead, because I can't just use the SDK here, as it won't appear and I need to have the Admob being set for the app, and yet I don't want to publish it.
So instead of the dialog I've presented, you need to add the implementation of Admob ad-consent to be shown.

If you want an APK, I can give you but in private. Will also need to explain you how to reach this situation. I can also send you a video showing the issue (but again, in private).

Sadly this website doesn't allow me to attach any ZIP/7z file. No idea how you want me to attach a sample here...
So here is via a website:
https://easyupload.io/69lcmv

Please fix the issue on the current website, so that people can attach files here. It doesn't even tell me what are the rules of what's allowed to be attached.

Mobile Ads SDK Forum Advisor

unread,
Jan 29, 2024, 2:29:08 PM1/29/24
to lbl...@gmail.com, google-adm...@googlegroups.com

Hi Liran,

There are many of difference in this example from our sample applications. This would require guess work on our end in order to rebuild your sample application with the bug. Please include a minimal sample application with steps on how we can replicate this bug.

Liran Barsisa

unread,
Jan 29, 2024, 7:37:30 PM1/29/24
to Google Mobile Ads SDK Developers
What do you mean by guess work? What difference are you talking about? I only added a single line and even this should be just removed. You have a clean app with just 2 Activities that need to be filled with duplicate code...
Just follow your own instructions to show the ad-consent dialog. You are supposed to do it using just 2 functions:

UserMessagingPlatform.getConsentInformation(...).requestConsentInfoUpdate

And:

UserMessagingPlatform.loadAndShowConsentFormIfRequired(activity)

That's it...
The only thing I can't provide you is the Admob account details. 

Here, updated snippet to add:

In manifest:
<uses-permission android:name="android.permission.INTERNET" />
...
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-0000000000000000~0000000000" />

In each Activity, remove the dialog I've added, and use this instead:

 val consentInformation: ConsentInformation =
            UserMessagingPlatform.getConsentInformation(this)
        val params = ConsentRequestParameters
            .Builder()
            .setTagForUnderAgeOfConsent(false)
        val debugGeography =
            ConsentDebugSettings.DebugGeography.DEBUG_GEOGRAPHY_EEA
        val debugSettings = ConsentDebugSettings.Builder(this)
            .setDebugGeography(debugGeography)
            .addTestDeviceHashedId(SystemUtils.getDeviceHashedId(this)!!.uppercase())
            .build()
        params.setConsentDebugSettings(debugSettings)
        val contentView = findViewById<View>(android.R.id.content)
        consentInformation.requestConsentInfoUpdate(this, params.build(), {
            val canRequestAdsAfterQuery = consentInformation.canRequestAds()
            if (canRequestAdsAfterQuery) {
                val msg = "can already show ads"
                Snackbar.make(this, contentView, msg, Snackbar.LENGTH_SHORT).show()
                Log.d("AppLog", msg)
                return@requestConsentInfoUpdate
            }
            UserMessagingPlatform.loadAndShowConsentFormIfRequired(this) { formError: FormError? ->
                if (formError != null) {
                    val msg =
                        "error showing ad-consent dialog:${formError.errorCode}-${formError.message}"
                    Snackbar.make(this, contentView, msg, Snackbar.LENGTH_SHORT).show()
                    Log.d("AppLog", msg)
                    return@loadAndShowConsentFormIfRequired
                }
                val msg ="ad-consent dialog result fetched. canRequestAds?${consentInformation.canRequestAds()}"
                Snackbar.make(this, contentView, msg, Snackbar.LENGTH_SHORT).show()
                Log.d("AppLog", msg)
            }
        }, { formError: FormError ->
            val msg ="error fetching ad-consent info:${formError.errorCode}-${formError.message}"
            Snackbar.make(this, contentView, msg, Snackbar.LENGTH_SHORT).show()
            Log.d("AppLog", msg)
        }
        )

In SystemUtils:

    @SuppressLint("HardwareIds")
    fun getDeviceHashedId(context: Context): String? {
        val md5 = Settings.Secure.getString(context.contentResolver, Settings.Secure.ANDROID_ID)
        try {
            val md = MessageDigest.getInstance("MD5")
            val array = md.digest(md5.toByteArray())
            val sb = StringBuilder()
            for (i in array.indices)
                sb.append(Integer.toHexString(array[i].toInt() and 0xFF or 0x100).substring(1, 3))
            //            Log.d("AppLog", "getDeviceIdForAdMobTestAds:$sb")
            return "$sb".uppercase(Locale.ROOT)
        } catch (e: NoSuchAlgorithmException) {
            e.printStackTrace()
        }
        return null
    }

Sadly this still isn't enough, and there are 2 bugs on the SDK related to this:
1. It claimed about the meta-data ,but presented an example that doesn't work and doesn't have "/>" to end the tag.
2. Even after adding the INTERNET permission, it claims I don't have it.

Please fix those bugs too, so that people could test out the SDK even without all the extras.
Here's a link to the project again, but please also fix this forum/issue-tracker to allow to upload files:

Liran Barsisa

unread,
Jan 29, 2024, 7:38:39 PM1/29/24
to Google Mobile Ads SDK Developers
Most important files here. 
files.zip
Reply all
Reply to author
Forward
0 new messages