dop2000 dop2000 - 1 year ago 52
Android Question

Android: AdMob view disrupts input from gamepad (onKey events stop working)

I’m displaying Admob banner ads in my game and I noticed that the AdView somehow messes up with the input from the gamepad.

For example buttons like X, A, L1, R1 stop working, they don't trigger

And other buttons generate incorrect key codes, for example when Y is pressed, instead of
I receive

This problem happens after I touch the screen (not the banner itself). If I don't touch the screen, the gamepad works fine.

So it seems like AdView is 'stealing' key events, or something like that.

I experimented with different AdView settings like
, position, tried assigning it custom KeyListener – nothing helps.

I tried 2 different gamepads and different android devices.

This problem disappears only when I remove the AdView or make it invisible...

Answer Source

Ok, seems like I found the solution. If I override dispatchKeyEvent and cancel dispatching onKey events to the AdView, then the gamepad works fine. Not sure if it's OK to do this, but it works.

public class MyAdView extends AdView {
    public MyAdView(Activity activity, AdSize adSize, String adUnitId) {
        super(activity, adSize, adUnitId);

    public boolean dispatchKeyEvent(KeyEvent event) {
        return false;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download