My interstitial ad is not working, Logcat only shows "The interstitial ad wasn't ready yet." I followed AdMob instructions but it doesn't start. As an additional note currently my app shows banner ads, no error appears. This is my code:
class MainActivity : AppCompatActivity() {
private var mInterstitialAd: InterstitialAd? = null
private final var TAG = "MainActivity"
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
MobileAds.initialize(this) {}
adView?.loadAd(adRequest)
if (mInterstitialAd != null) {
InterstitialAd.load(this, AD_UNIT_ID, adRequest, object : InterstitialAdLoadCallback() {
override fun onAdFailedToLoad(adError: LoadAdError) {
Log.d(TAG, adError.toString())
mInterstitialAd = null
}
override fun onAdLoaded(interstitialAd: InterstitialAd) {
Log.d(TAG, "Ad was loaded")
mInterstitialAd = interstitialAd
}
})
mInterstitialAd?.fullScreenContentCallback = object: FullScreenContentCallback() {
override fun onAdClicked() {
// Called when a click is recorded for an ad.
Log.d(TAG, "Ad was clicked.")
}
override fun onAdDismissedFullScreenContent() {
// Called when ad is dismissed.
Log.d(TAG, "Ad dismissed fullscreen content.")
mInterstitialAd = null
}
override fun onAdFailedToShowFullScreenContent(p0: AdError) {
// Called when ad fails to show.
Log.e(TAG, "Ad failed to show fullscreen content.")
mInterstitialAd = null
}
override fun onAdImpression() {
// Called when an impression is recorded for an ad.
Log.d(TAG, "Ad recorded an impression.")
}
override fun onAdShowedFullScreenContent() {
// Called when ad is shown.
Log.d(TAG, "Ad showed fullscreen content.")
}
}
mInterstitialAd?.show(this)
} else {
Log.d("TAG", "The interstitial ad wasn't ready yet.")
}
}
}