AdMob Ad Ignores First Click - Workaround

One of my fellow developers recently noticed a bug in our Google AdMob ads: the first time you click an ad, nothing happens; on subsequent clicks, it opens the ad in a web activity, as expected... but when you press the ad, a narrow blue bar appears across the bottom quarter of the ad, instead of the standard highlight that covers the entire PublisherAdView rectangle.
After some research, we discovered that this was only happening on Android 4.3 and earlier. When we tested on Android 4.4.2 and later, the ad responded to the first click, and the blue-highlight feedback you see while pressing the ad worked as expected, filling the entire height of the ad.
Our app was using Google Play Services 6.1.71. I upgraded to the latest, which is currently 6.5.87, and discovered that the bug is still there.
Some web searches turned up this item on Stack Overflow, which is clearly similar. It makes no mention of the narrow blue bar, but the problem with the first click being swallowed was the same, so I tried the recommended fix, which is to set descendantFocusability to "blocksDescendants" in the root ViewGroup that contains the ad. It fixed the problem where the first click is ignored. The blue bar still shows up, instead of a highlight that covers the entire ad, but I can live with that.
We have multiple layouts that contain AdMob ads, but they all use a shared wrapper view, which is responsible for instantiating the PublisherAdView object. Rather than muck with descendantFocusability settings in multiple XML layout files, I tried setting the property in code, directly on the PublisherAdView instance, and -- as I had hoped -- that has the same effect.
Here's the code (sorry... postach.io drops the leading whitespace from my Evernote note, even inside pre tags):
if(Build.VERSION.SDK_INT <= 18) {
// hack to prevent problem where ad requires two clicks
mAdView.setDescendantFocusability(FOCUS_BLOCK_DESCENDANTS);
}
From there, I tried to report the bug to Google, and I eventually stumbled across this depressing post, the upshot of which is that there's no good place to do so. Way to go, Google. (I'm reminded of Microsoft in the early 2000s.)
If you know of a good place to report this bug, please do so, and/or tell me how to.
Meanwhile, I hope this helps you work around whatever issue is occurring inside the PublisherAdView that is prevented by blocking descendants from receiving focus. Note: this workaround seems perfectly reasonable for the app where it's used, because it is a touch-only app where focus isn't a concern. If your Android app supports navigation using four-way arrows or another key-based mechanism where focus is an essential part of user input (such as the remote on a Nexus Player), this workaround might cause its own problems.

comments powered by Disqus