Prevent Pre-Launch Test to click banner in jetpack compose

70 Views Asked by At

When I was looking at the pre-launch report of my app, as well in play console as in firebase, I got the feeling that the ads where being clicked. Is there a way to detect test devices and eventually not display the banner?

1

There are 1 best solutions below

0
miqrc On BEST ANSWER

The automated tests do click on the ads and sometimes even open the internet browser, so the pre-launch report is messed up. Also, this triggers actual ad impressions, which is against the AdMob policies.

To workaround this, the only solution I found is to detect whether the app is running on a test device and hide the ads accordingly.

To check if you are on a test device:

private fun isTestDevice(): Boolean {
    val testLabSetting: String? = Settings.System.getString(contentResolver, "firebase.test.lab")
    return "true" == testLabSetting
}

To display the ads only on non-test devices:

if(!isTestDevice()) {
    AdViewCompose(adUnitId = adUnitId)
}