如何知道是否AdMob的广告已经被加载 [英] How to know if AdMob ad has been loaded
问题描述
我的Andorid应用程序可以离线和在线。它显示的广告,当它处于联机模式。 在这样一个场景,它是工作在离线模式,用户在切换互联网连接,我想知道是否已经装入该广告。如果没有,那么我会加载一个新的广告。我看着AdMob的API(AD浏览报班),但无法找到的东西,做到这一点。
下面是执行我的 AdListener
据@Hounshell答案。但是,没有方法在这里实现都得到执行。
adView.setAdListener(新AdListener(){
@覆盖
公共无效onReceiveAd(广告为arg0){
Toast.makeText(法,广告收,Toast.LENGTH_LONG).show();
}
@覆盖
公共无效于presentScreen(广告为arg0){
}
@覆盖
公共无效onLeaveApplication(广告为arg0){
// TODO自动生成方法存根
}
@覆盖
公共无效onFailedToReceiveAd(广告为arg0,错误code ARG1){
Toast.makeText(行为,无法接受广告,Toast.LENGTH_LONG).show();
}
@覆盖
公共无效onDismissScreen(广告为arg0){
// TODO自动生成方法存根
}
});
和main.xml中的一部分,涵盖了AD浏览报
<的FrameLayout
机器人:layout_width =FILL_PARENT
机器人:layout_height =50dp
>
< com.google.ads.AdView
的xmlns:广告=http://schemas.android.com/apk/lib/com.google.ads
机器人:ID =@ + ID / AD浏览报
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
广告:adSize =大旗
广告:adUnitId =XXXXXXXXXXXXXXXX
广告:loadAdOnCreate =真/>
< /的FrameLayout>
从的https://developers.google.com/mobile-ads-sdk/docs/android/intermediate#adlistener
AdView.setAdListener(新AdListener(){
//实现AdListener
});
您AdListener的 onReceiveAd()
时,广告可会叫, onFailedToReceiveAd()
将被称为焕广告不可用code解释为什么(包括网络无法使用,没有填充)
更新:
基本相同的答案,新的URL: https://developers.google.com / AdMob的/安卓/旗帜?HL = EN
My Andorid app works offline and online. It displays ads when it is in online mode. In a scenario where it is working in offline mode and user switches the internet connectivity on, I want to know if the ad is already loaded. If not, then I would load a new ad. I looked at AdMob API (AdView class) but could not find something that does this.
Here is the implementation of my AdListener
according to the answer from @Hounshell. But none of the methods implemented here are getting executed.
adView.setAdListener(new AdListener() {
@Override
public void onReceiveAd(Ad arg0) {
Toast.makeText(act, "Ad received",Toast.LENGTH_LONG).show();
}
@Override
public void onPresentScreen(Ad arg0) {
}
@Override
public void onLeaveApplication(Ad arg0) {
// TODO Auto-generated method stub
}
@Override
public void onFailedToReceiveAd(Ad arg0, ErrorCode arg1) {
Toast.makeText(act, "Failed to receive Ad",Toast.LENGTH_LONG).show();
}
@Override
public void onDismissScreen(Ad arg0) {
// TODO Auto-generated method stub
}
});
And part of main.xml that covers the AdView
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="50dp"
>
<com.google.ads.AdView
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/adView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
ads:adSize="BANNER"
ads:adUnitId="xxxxxxxxxxxxxxxx"
ads:loadAdOnCreate="true" />
</FrameLayout>
From https://developers.google.com/mobile-ads-sdk/docs/android/intermediate#adlistener
AdView.setAdListener(new AdListener() {
// Implement AdListener
});
Your AdListener's onReceiveAd()
will be called when an ad is available, onFailedToReceiveAd()
will be called whan an ad isn't available with a code explaining why (including network not available and no fill)
Update:
Same basic answer, new URL: https://developers.google.com/admob/android/banner?hl=en
这篇关于如何知道是否AdMob的广告已经被加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!