隐藏/显示AdView后,AdMob不会刷新广告 [英] AdMob does not refresh the ad after hiding/showing AdView

查看:188
本文介绍了隐藏/显示AdView后,AdMob不会刷新广告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将AdMob广告添加到我的应用程序中,但是根据设备的互联网连接状态,我无法显示/隐藏广告。当我打开设备并打开WiFi时,广告会正确显示;当我关闭WiFi时,广告也会完全隐藏。但是,当我从没有互联网状态转到WiFi / 3G时,广告上没有显示。相反,我在Logcat中收到了这样的消息:

I would like to add AdMob ads to my application, but I have a problem with showing/hiding them depending on the internet connection status of the device. When I turn on my device with WiFi turned on the ad is shown correctly, when I turn the WiFi off, the ad is hiding also corectly. But when I go from "no internet" state to WiFi/3G on the ad is not showing. Instead I get suchmessages in Logcat:

04-15 13:16:03.688    8813-8813/com.package.app I/Ads﹕ Ad is not visible. Not refreshing ad.
04-15 13:16:03.688    8813-8813/com.package.app I/Ads﹕ Scheduling ad refresh 60000 milliseconds from now.

活动代码:

@Override
    protected void onCreate(Bundle savedInstanceState) {
    /***/   

        mAdView = (AdView) findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().build();
        mAdView.loadAd(adRequest);
        mAdView.setAdListener(new AdListener() {
            @Override
            public void onAdLoaded() {
                mAdView.setVisibility(View.VISIBLE);
                super.onAdLoaded();
            }

            @Override
            public void onAdFailedToLoad(int errorCode) {
                super.onAdFailedToLoad(errorCode);
                mAdView.setVisibility(View.GONE);
            }
        });
    }
@Override
protected void onResume() {
        super.onResume();
        if (mAdView != null) {
            mAdView.resume();
        }
    }

@Override
    protected void onPause() {
        super.onPause();
        if (mAdView != null) {
            mAdView.pause();
        }
    }

@Override
    protected void onDestroy() {
        super.onDestroy();

        if (mAdView != null) {
            mAdView.destroy();
        }
    }

我想打开广告并制作 AdView 在用户打开互联网连接时可见,而在用户断开互联网连接时隐藏。我的方法有什么问题?

I would like to turn the ads on and make the AdView visible when the user turns the internet connection on, and hide it when the user loses the internet connection. What's wrong with my approach? Is it possibile to do this without internet connectivity state listener?

推荐答案

如果要检测用户何时更改其连接,是否可以进行此操作?应该注册 BroadcastReceiver ,请检查
为了隐藏/显示 AdView ,我使用了一个 RelativeLayout 作为所有者,而我将其隐藏,而不是 AdView

If you want to detect when the user changes his connection, you should register a BroadcastReceiver, check this.
And for hiding/showing AdView, I am using one RelativeLayoutas holder, and I am hiding it instead of AdView.

这篇关于隐藏/显示AdView后,AdMob不会刷新广告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆