Reputation: 6572
how can I understand If user clicked on admob ad? ontouch listener didnt 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);
second question is how to manage ads If they on the top of a button or something touching? android works on many phones and can't test all.. just read that's forbidden..
Upvotes: 5
Views: 3650
Reputation: 8931
The SDK provides you with callbacks when important events occur. The onPresentScreen
method will get called prior to exiting your app and going to the click through url. Just have your class implement AdListener and then call adView.setAdListener(this);
Upvotes: 6
Reputation: 1787
First of all why do you need to see if the user has clicked on ad or not? If he has clicked, then the revenue generated 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. Just define the standard ad code in your XML file where you want the ad to display. Defining it in xml file will get you rid of your issue of the ad being attached to the button. You can place it wherever you want.
Upvotes: -3