**I tried it lots of times but I failed. I am new to Android development. Is my code correct? Please help me. I created a class for load the ads loading work : **
class InterstitialAds {
var mInterstitialAd: InterstitialAd? = null
fun interAds(context: Context){
MobileAds.initialize(context)
var adRequest = AdRequest.Builder().build()
InterstitialAd.load(context,"ca-app-pub-3940256099942544/1033173712", adRequest, object : InterstitialAdLoadCallback() {
override fun onAdFailedToLoad(adError: LoadAdError) {
adError?.toString()?.let { Log.d(ContentValues.TAG, it) }
mInterstitialAd = null
}
override fun onAdLoaded(interstitialAd: InterstitialAd) {
mInterstitialAd = interstitialAd
}
})
}
}
** In Adapter : **
holder.thumbnail.setOnClickListener {
val interstitialAds = InterstitialAds()
interstitialAds.interAds(context)
if (interstitialAds.mInterstitialAd != null) {
interstitialAds.mInterstitialAd!!.show(context as Activity)
interstitialAds.mInterstitialAd!!.fullScreenContentCallback =
object : FullScreenContentCallback() {
override fun onAdDismissedFullScreenContent() {
// Called when ad is dismissed.
interstitialAds.mInterstitialAd = null
interstitialAds.interAds(context)
progressBar.visibility = View.VISIBLE
webView.visibility = View.VISIBLE
thumnail.visibility = View.GONE
val webSettings: WebSettings = webView.settings
webSettings.javaScriptEnabled = true
webView.webViewClient = object : WebViewClient() {
override fun onPageFinished(view: WebView?, url: String?) {
progressBar.visibility = View.GONE
fullButton.visibility = View.VISIBLE
}
}
webView.loadData(item.videoEmbed!!, "text/html", "utf-8")
}
}
}
**Can anyone help me to solve this issue. Is my code correct? Please help me. I created a class for load the ads loading work **
If your app is in production, Use
RequestConfiguration.Builder().setTestDeviceIds(Arrays.asList("455FDC94B1F5B4415BD853EEB4FFCDB0"))before
MobileAds.initialize(context)If you do not know TestDeviceId then search safeDK Device ID in logcat.
If that does not work then change your package name for testing purposes. And change it back before releasing a new update