点击后禁用 admob 广告?
大家好~点击后可以禁用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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您的类实现了 AdListener,您可以将禁用代码放入 onDismissScreen() 中。当用户关闭广告并返回到您的应用程序时,会调用此方法。
例如:
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:
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.
重写 onAdLeftApplication 并设置一个变量。然后您可以根据该变量
检查文档 跳过加载广告
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
check documentation
https://developers.google.com/android/reference/com/google/android/gms/ads/AdListener.html#onAdLeftApplication()