Facebook Audience Network 和 Admob 同时 activity

Facebook Audience Network and Admob at same activity

我想同时使用两个广告网络,意思是如果 admob 广告未加载/显示,那么我想展示 facebook 广告。

我可以在同一屏幕上使用 facebook 横幅广告和 admob 插页式广告吗(这样安全吗?)

public class SomeActivity 扩展了 AppCompatActivity {

private InterstitialAd mInterstitialAd;
private com.facebook.ads.InterstitialAd fbIntAd;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.home_page);
    initAdMobInt();
    initFBIntAd();
    TextView showAds =  findViewById(R.id.show_ads);
    showAds.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (fbIntAd.isAdLoaded()
                    && !fbIntAd.isAdInvalidated()) {
                fbIntAd.show();
            } else if (mInterstitialAd.isLoaded()) {
                adMobIntAd.show();
            }   else {
                // perform required action
            }

        }
    });
}

private void initAdMobInt() {
    adMobIntAd = new InterstitialAd(this);
    adMobIntAd.setAdUnitId(getString(R.string.admob_int_ad));
    adMobIntAd.loadAd(new AdRequest.Builder().build());

    adMobIntAd.setAdListener(new AdListener() {
        @Override
        public void onAdClosed() {
            // Load the next interstitial.
            adMobIntAd.loadAd(new AdRequest.Builder().build());
            // Perform the action here
        }

        @Override
        public void onAdFailedToLoad(int i) {
            adMobIntAd.loadAd(new AdRequest.Builder().build());
        }

        @Override
        public void onAdLeftApplication() {
            adMobIntAd.loadAd(new AdRequest.Builder().build());
        }
    });
}

private void initFBIntAd() {
    fbIntAd = new com.facebook.ads.InterstitialAd(this, getString(R.string.fb_int_ad));
    // Set listeners for the Interstitial Ad
    fbIntAd.setAdListener(new InterstitialAdListener() {
        @Override
        public void onInterstitialDisplayed(Ad ad) {
        }

        @Override
        public void onInterstitialDismissed(Ad ad) {
            //Perform action here .....
            fbIntAd.loadAd();
        }

        @Override
        public void onError(Ad ad, AdError adError) {
            // Ad error callback
            fbIntAd.loadAd();
        }

        @Override
        public void onAdLoaded(Ad ad) {
        }

        @Override
        public void onAdClicked(Ad ad) {
            // Ad clicked callback
        }

        @Override
        public void onLoggingImpression(Ad ad) {
            // Ad impression logged callback
        }
    });

    fbIntAd.loadAd();
}

}