ChartBoost插页式横幅广告未在Android Studio应用中显示

时间:2017-02-01 12:17:21

标签: android ads interstitial chartboost

我正在使用Android Studio处理Android应用。我在我的Android应用中使用ChartBoost插页式横幅广告。 我使用ChartBoost Android SDK集成链接为我的代码集成了ChartBoost SDK; 我已经正确地遵循了chartboost链接&放置appId& strings.xml中的appsignature。这是我的MainActivity.java

import com.chartboost.sdk.CBLocation;
import com.chartboost.sdk.Chartboost;
import com.chartboost.sdk.ChartboostDelegate;
import com.chartboost.sdk.Libraries.CBLogging;

public class MainMenu extends Activity {

    private InterstitialAd mInterstitialAd, mInterstitialAd1;

    private static final String TAG = "Chartboost";
    // This is the object for Startapp Ads Banner
    private StartAppAd startAppAd = new StartAppAd(this);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //This is the AppID for Startup Ads Banner
        StartAppSDK.init(this, "xxxxxxxxx", false);
        setContentView(R.layout.activity_menu);

        Chartboost.startWithAppId(this, getResources().getString(R.string.appId), getResources().getString(R.string.appSignature));
        Chartboost.setLoggingLevel(CBLogging.Level.ALL);
        Chartboost.setDelegate(delegate);
        Chartboost.onCreate(this);


        if ( Chartboost.hasInterstitial(CBLocation.LOCATION_DEFAULT) ) {
            Chartboost.showInterstitial(CBLocation.LOCATION_DEFAULT);
        } else {
            Chartboost.cacheInterstitial(CBLocation.LOCATION_DEFAULT);
        }


        AdView mAdView = (AdView) findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().build();
        mAdView.loadAd(adRequest);
        mInterstitialAd = new InterstitialAd(this);
        mInterstitialAd.setAdUnitId(getResources().getString(R.string.inter_ad_unit_id));
        mInterstitialAd.setAdListener(new AdListener() {
            @Override
            public void onAdClosed() {
                requestNewInterstitial();
            }
        });
        requestNewInterstitial();

        mInterstitialAd1 = new InterstitialAd(this);
        mInterstitialAd1.setAdUnitId(getResources().getString(R.string.inter_ad_unit_id));
        mInterstitialAd1.setAdListener(new AdListener() {
            @Override
            public void onAdClosed() {
                requestNewInterstitial1();
            }
        });
        requestNewInterstitial1();

        startAppAd.loadAd(new AdEventListener() {
            @Override
            public void onReceiveAd(Ad ad) {
            }

            @Override
            public void onFailedToReceiveAd(Ad ad) {
            }
        });


        Button shareIt = (Button) findViewById(R.id.shareIt);
        shareIt.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                shareIt();
            }
        });


    }

    //-------------- Shareit Button ---------------//
    private void shareIt() {
        mInterstitialAd.show();
        Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
        sharingIntent.setType("text/plain");
        sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Business and Visiting Cards Maker");
        sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, "https://play.google.com/store/apps/details?id=com.ata.business.visiting.cards.maker");
        startActivity(Intent.createChooser(sharingIntent, "Share via"));
    }

    public void click_card(View v) {
        mInterstitialAd.show();
        Intent intent = new Intent(this, MainActivity.class);
        this.startActivity(intent);
    }

    private ChartboostDelegate delegate = new ChartboostDelegate() {

        @Override
        public boolean shouldRequestInterstitial(String location) {
            Log.i(TAG, "SHOULD REQUEST INTERSTITIAL '" + (location != null ? location : "null"));
            return true;
        }

        @Override
        public boolean shouldDisplayInterstitial(String location) {
            Log.i(TAG, "SHOULD DISPLAY INTERSTITIAL '" + (location != null ? location : "null"));
            return true;
        }

        @Override
        public void didCacheInterstitial(String location) {
            Log.i(TAG, "DID CACHE INTERSTITIAL '" + (location != null ? location : "null"));
        }

    };

    @Override
    protected void onStart() {
        super.onStart();
        Chartboost.onStart(this);
    }

    @Override
    public void onResume() {
        super.onResume();
        Chartboost.onResume(this);
    }

    @Override
    public void onPause() {
        super.onPause();
        Chartboost.onPause(this);
    }

    @Override
    public void onStop() {
        super.onStop();
        Chartboost.onStop(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Chartboost.onDestroy(this);
    }


    private void requestNewInterstitial() {
        AdRequest adRequest = new AdRequest.Builder().build();
        mInterstitialAd.loadAd(adRequest);
    }

    private void requestNewInterstitial1() {
        AdRequest adRequest = new AdRequest.Builder().build();
        mInterstitialAd1.loadAd(adRequest);
    }

    @Override
    public boolean onKeyUp(int keyCode, KeyEvent msg) {
        switch (keyCode) {
            case (KeyEvent.KEYCODE_BACK):
                Intent intent = new Intent(this, ExitPanel.class);
                startActivity(intent);
                startAppAd.showAd();
                finish();
                return true;
        }
        return false;
    }
}

在Android Studio中,Logcat插页式横幅已加载,但在我的Android设备中,非插页式横幅广告未显示。 在ChartBoost Dashboard中,非页内广告横幅为纵向表格。 点击率,展示次数和展示次数下载正在显示。 但问题是插页式横幅没有在MainActivity.java中显示

任何人都可以告诉我应该使用哪个位置&为什么Interstitial Banner没有在我的Android设备或模拟器中显示的问题是什么? 我也试过Hotspot Sheild VPN ......但它没用?

1 个答案:

答案 0 :(得分:0)

 if (Chartboost.hasInterstitial(CBLocation.LOCATION_DEFAULT) ) {
            Chartboost.showInterstitial(CBLocation.LOCATION_DEFAULT);
  } else {
      Chartboost.cacheInterstitial(CBLocation.LOCATION_DEFAULT);
 }

这只是Chartboost的非页内广告的一部分。你在做什么,当你的活动开始时它会检查Chartboost是否有任何位置广告位置 CBLocation.LOCATION_DEFAULT 然后它返回false,因为你还没有请求任何此类广告。然后,通过else部分,您为 CBLocation.LOCATION_DEFAULT 位置请求插页式广告。

过了一段时间,可能是您有插页式广告,然后当您检查Chartboost.hasInterstitial(CBLocation.LOCATION_DEFAULT)的值时返回true和 Chartboost.showInterstitial(CBLocation.LOCATION_DEFAULT);向您展示广告。

使用代表的方式告诉您,您的广告已准备好展示。