简体   繁体   English

如果用户具有捐赠密钥,则隐藏AdView

[英]Hide AdView if user has donation key

I have started integrating Airpushes banner ad "AdView" into my application and have it working well, however I know want to be able to disable the ads if the user has bought my donation key, I have this already set up and just set if the user has the key via a shared preference. 我已经开始将Airpushes横幅广告“ AdView”集成到我的应用程序中,并且效果良好,但是我知道如果用户购买了我的捐赠钥匙,我希望能够禁用广告,我已经设置好了,如果用户通过共享首选项拥有密钥。

However when I do the below the ad still displays, in my oncreate I have: 但是,当我执行以下操作时,广告仍然显示,在我的oncreate中,我有:

AdView ad = (AdView) findViewById(R.id.guideAdView);
        if (AppPreferences.getPrefs().getBoolean("full", false)){
            ad.setVisibility(View.GONE);
        }

        AdCallbackListener adCallbackListener = new AdCallbackListener() {

            @Override
            public void onSDKIntegrationError(String message) {
                // Here you will receive message from SDK if it detects any
                // integration issue.
            }

            public void onSmartWallAdShowing() {
                // This will be called by SDK when it’s showing any of the
                // SmartWall ad.
            }

            @Override
            public void onSmartWallAdClosed() {
                // This will be called by SDK when the SmartWall ad is closed.
            }

            @Override
            public void onAdError(String message) {
                // This will get called if any error occurred during ad serving.
            }

            @Override
            public void onAdCached(AdType arg0) {
                // This will get called when an ad is cached.

            }

            @Override
            public void onVideoAdFinished() {
                // TODO Auto-generated method stub

            }

            @Override
            public void onVideoAdShowing() {
                // TODO Auto-generated method stub

            }
        };

        if (airPlay == null)
            airPlay = new AirPlay(this, adCallbackListener, false); 

I know the if (AppPreferences.getPrefs().getBoolean("full", false)) works fine because this is used else where in the activity to display other information if the user does have the full key. 我知道if (AppPreferences.getPrefs().getBoolean("full", false))可以正常工作,因为如果用户确实具有完整键,则可以在活动中的其他位置使用它来显示其他信息。 So the question is why goes the above not work for the adView? 所以问题是为什么上面的方法不适用于adView?

I have never used airpush but why don't you just not run the ad code if the user has a key. 我从未使用过airpush,但是如果用户有密钥,为什么不就不运行广告代码呢?

There is no point setting up all of the listeners and the new AirPlay object if the ads are not to be displayed. 如果不显示广告,则没有必要设置所有侦听器和新的AirPlay对象。

eg: 例如:

    if (AppPreferences.getPrefs().getBoolean("full", false)){
        // Do not show ads
        AdView ad = (AdView) findViewById(R.id.guideAdView);    
        ad.setVisibility(View.GONE);
    } else {
        // Show Ads
        // Set up listener (omitted from this example for clarity)
        if (airPlay == null) airPlay = new AirPlay(this, adCallbackListener, false); 
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM