Admob onclicked event

How can I understand if a user clicked on an admob ad? the ontouch listener did not work.

Display display = ((WindowManager) this.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); int width = display.getWidth(); int height = display.getHeight(); Window window = getWindow(); adsLayout = new RelativeLayout(this); RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(//width,height); RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.FILL_PARENT); adsLayout.setGravity(Gravity.BOTTOM); adView = new AdView(this, AdSize.BANNER, "XXX"); com.google.ads.AdRequest adRequest1 = new com.google.ads.AdRequest(); adRequest1.addTestDevice(com.google.ads.AdRequest.TEST_EMULATOR); // Emulator int adwidth = height; adView.setPadding((width - adwidth) / 2, 0, 0, 0); adView.loadAd(adRequest1); adsLayout.addView(adView); adView.setOnTouchListener( (android.view.View.OnTouchListener) mOnTouchListener ); window.addContentView(adsLayout,lp2); 

The second question: how to manage ads if they are at the top of the button or something related? Android runs on many phones and cannot test everything .. just read what is forbidden.

+4
source share
2 answers

The SDK provides you with callbacks when important events occur. The onPresentScreen method will be called before exiting your application and navigating to the click URL. Just ask your class to implement AdListener, and then call adView.setAdListener(this);

+6
source

First of all, why do you need to find out if the user clicked on the ad or not? If he clicked, then the revenue received per click will be reflected in your Admob account. $ 0.01 per click.

Secondly, you do not need to define admob code in your Java classes. Simply define the standard ad code in your XML file where you want the ad to appear. Defining it in an xml file will save you from a problem with a declaration attached to a button. You can place it wherever you want.

-2
source

Source: https://habr.com/ru/post/1390412/


All Articles