Android : AdMob onClickListener

后端 未结 4 752
忘掉有多难
忘掉有多难 2021-01-03 03:15

I display into my android application AdMob\'s banners. I would like that when the user click on the banner it gone. I have try the code AdView.setOnC

4条回答
  •  走了就别回头了
    2021-01-03 03:56

    Try using AdMob's adListener to listen for events.

    public interface AdListener {
      public void onReceiveAd(Ad ad);
      public void onFailedToReceiveAd(Ad ad, AdRequest.ErrorCode error);
      public void onPresentScreen(Ad ad);
      public void onDismissScreen(Ad ad);
      public void onLeaveApplication(Ad ad);
    }
    

    Have your class implement the listener, and then add the listener to the adView:

    adView.setAdListener(this);
    

    Implement the onDismissScreen event, which occurs once your app resumes control after handling the ad click. At this point, you can remove the AdView, and you will have gotten credit for the click.

    @Override
    public void onDismissScreen(Ad ad) {
      if (adView != null) {
        adView.destroy();
      }
    }
    

提交回复
热议问题