Is there any way to detect when the user taps on the interstitial ads? I tried but did not find any callbacks for detecting interstitial ad clicks.
Any workaround for detecting the same would also be very helpful.
I want to detect ads click to prevent users from generating fake clicks for interstitial ads.
Google added back the removed interstitialAd callback onAdClicked() on SDK 20.4.0. Looks like they removed it and 6 months later realized they messed up and decided to add it back :)
Added the onAdClicked() callback to FullScreenContentCallback.
See the AdMob SDK release notes for details.
I’ve found that upgrading AdMob SDK to the latest version is a must.
You can utilize the combination of ActivityLifecycleCallbacks and WindowCallback.
ActivityLifecycleCallbacks enables you to observe every Activity lifecycle event that occurs in your app. All in one place.WindowCallback enables you to intercept many window events. One of the events that gets fired by the system that we are particularly interested in is dispatchTouchEvent.Now, here is the strategy:
GlobalActivityLifecycleListener in the Application classclass MyApplication : Application() {
    override fun onCreate() {
        super.onCreate()
        registerActivityLifecycleCallbacks(GlobalActivityLifecycleListener())
    }
}
AdWindowCallbacksclass GlobalActivityLifecycleListener : Application.ActivityLifecycleCallbacks {
    //...
    override fun onActivityResumed(activity: Activity) {
        if (isAdActivity(activity)) {
            registerWindowCallbacks(activity)
        }
    }
    
    private fun registerWindowCallbacks(activity: Activity) {
        val currentWindow = activity.window
        /*This is needed to forward the events from our callback back to the original
        callback after we are done with the processing*/
        val originalCallbacks = currentWindow.callback
        currentWindow.callback = AdWindowCallbacks(originalCallbacks)
    }
}
class AdWindowCallbacks(private val originalCallback: Window.Callback) : Window.Callback {
    //...
    override fun dispatchTouchEvent(event: MotionEvent?): Boolean {
        //TODO process user touch event
        return originalCallback.dispatchTouchEvent(event)
    }
}
From there, you can detect the common gestures and act accordingly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With