点击后禁用 admob 广告?

发布于 2024-11-01 21:11:19 字数 667 浏览 0 评论 0原文

大家好~点击后可以禁用admob广告吗? 我尝试使用此代码,但没有任何反应,有人可以帮我吗? 提前致谢

    final LinearLayout layout = ( LinearLayout )findViewById( R.id.adslayout ) ;
    final AdView adView = new AdView( this, AdSize.BANNER, "a11111111b9041" ) ;
    layout.addView( adView ) ;
    adView.setVisibility( View.VISIBLE ) ;
    adView.loadAd( new AdRequest() ) ;

    adView.setOnClickListener( new View.OnClickListener()
    { 
       public void onClick( View v ) 
      {
            layout.removeAllViews() ;
            adView.setVisibility( View.GONE ) ;
             ed.putBoolean( "adsClicked", true ) ;
             ed.commit() ;
      } // onClick() 
    }  );

Hi All ~ Is that possible to disabled admob ads after clicked ?
I tried with this code but nothing happened, can anyone please help me out ?
Thanks in advance

    final LinearLayout layout = ( LinearLayout )findViewById( R.id.adslayout ) ;
    final AdView adView = new AdView( this, AdSize.BANNER, "a11111111b9041" ) ;
    layout.addView( adView ) ;
    adView.setVisibility( View.VISIBLE ) ;
    adView.loadAd( new AdRequest() ) ;

    adView.setOnClickListener( new View.OnClickListener()
    { 
       public void onClick( View v ) 
      {
            layout.removeAllViews() ;
            adView.setVisibility( View.GONE ) ;
             ed.putBoolean( "adsClicked", true ) ;
             ed.commit() ;
      } // onClick() 
    }  );

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

半窗疏影 2024-11-08 21:11:19

如果您的类实现了 AdListener,您可以将禁用代码放入 onDismissScreen() 中。当用户关闭广告并返回到您的应用程序时,会调用此方法。

例如:

public class Advertisement implements AdListener{

    // more code here

    @Override
    public void onDismissScreen(Ad arg0) {
        mainLayout.removeView(adView);
    }

    // more code here

}

If your class implements AdListener, you can put your disable code into onDismissScreen(). This method is called when the user closes the advertisement and returns to your app.

For example:

public class Advertisement implements AdListener{

    // more code here

    @Override
    public void onDismissScreen(Ad arg0) {
        mainLayout.removeView(adView);
    }

    // more code here

}
泼猴你往哪里跑 2024-11-08 21:11:19

AdView 小部件有一种未记录的 (?) 方法,即 stopLoading
我认为这应该可以完成任务。

简单地隐藏小部件并不能阻止它继续请求广告。

There is one undocumented (?) method for the AdView widget which is stopLoading.
I think that should do the job.

Simply hiding the widget does not stop it from keep requesting Ads.

鸵鸟症 2024-11-08 21:11:19

重写 onAdLeftApplication 并设置一个变量。然后您可以根据该变量

interstitial = new InterstitialAd(this);
interstitial.setAdUnitId(MY_AD_UNIT_ID);

interstitial.setAdListener(new AdListener() {
   @Override
   public void onAdLeftApplication(){
       user_has_clicked_ads = true;
   }

检查文档 跳过加载广告
https://developers.google .com/android/reference/com/google/android/gms/ads/AdListener.html#onAdLeftApplication()

Override onAdLeftApplication and set a variable. Then you can skip loading ads depending on that variable

interstitial = new InterstitialAd(this);
interstitial.setAdUnitId(MY_AD_UNIT_ID);

interstitial.setAdListener(new AdListener() {
   @Override
   public void onAdLeftApplication(){
       user_has_clicked_ads = true;
   }

check documentation
https://developers.google.com/android/reference/com/google/android/gms/ads/AdListener.html#onAdLeftApplication()

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文