Skip to content

Bug: Full screen ads sample don't look well, and even the "native ad validator" has a warning about them... #3

@AndroidDeveloperLB

Description

@AndroidDeveloperLB

Similar to here. Meaning:

The Java sample and the Kotlin sample have the same issue I've presented here, of the card taking over a huge portion of the media (on top of it), together with the navigation bar on top of the card, and this time it also has Admob's own ad-validator warning about it (which for some reason is also in a weird location). Also on dark theme the texts color is quite a bad choice...

Look:

Image Image Image

Speaking about dark theme, the splash screen also doesn't look well...

Image

The way the sample is designed with ViewModel is also very buggy, as it updates the state of having the ad loaded only in the current Activity, leaving the ViewModel to be just like a cache of the ad, instead of actually being the one responsible about the states and loading of the ad.

I've also noticed that still the sample uses TEST_DEVICE_HASHED_ID instead of just calculating it or having an API to have "setCurrentDeviceAsTestDevice. I don't understand why not doing it in code instead of telling us to check the ID and put it in code, as such a thing can change and we could have multiple devices (and also emulator).
I suggest using something like this instead:

val deviceIds = arrayListOf(AdRequest.DEVICE_ID_EMULATOR)
SystemUtils.getDeviceHashedId(context)?.let { deviceIds.add(it) }
    fun getDeviceHashedId(context: Application): 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.ENGLISH)
        } catch (e: NoSuchAlgorithmException) {
            e.printStackTrace()
        }
        return null
    }

You are also using some weird version of Admob ads SDK that doesn't have AdRequest.DEVICE_ID_EMULATOR, which is documented here:

https://developers.google.com/admob/android/reference/com/google/android/gms/ads/AdRequest#DEVICE_ID_EMULATOR()

So, in SplashActivity (why Activity? We have splash API...), I changed it to:

            val deviceIds = arrayListOf("B3EEABB8EE11C2BE770B684D95219ECB")
            SystemUtils.getDeviceHashedId(application)?.let { deviceIds.add(it) }
            // Set your test devices.
            MobileAds.setRequestConfiguration(
                RequestConfiguration.Builder()
                    .setTestDeviceIds(deviceIds)
                    .build()
            )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions