Android Admob zeigt keine Interstitial-Anzeige mit Test-App-ID in Kotlin anAndroid

Forum für diejenigen, die für Android programmieren
Anonymous
 Android Admob zeigt keine Interstitial-Anzeige mit Test-App-ID in Kotlin an

Post by Anonymous »

Dies ist meine SettingActivity-Datei, in der ich versuche, die Anzeige über eine Anzeigenschaltfläche anzuzeigen, aber jedes Mal, wenn ich versuche, sie auszuführen, wird in Logcat angezeigt, dass die Interstitial-Anzeige nicht geladen ist. Was könnte das wahrscheinliche Problem sein und wie kann ich es beheben?

Code: Select all

import android.content.Intent
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.util.Log
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import com.example.cointoss.databinding.ActivitySettingBinding
import com.google.android.gms.ads.AdRequest
import com.google.android.gms.ads.FullScreenContentCallback
import com.google.android.gms.ads.LoadAdError
import com.google.android.gms.ads.MobileAds
import com.google.android.gms.ads.interstitial.InterstitialAd
import com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback

class SettingActivity : AppCompatActivity() {
private lateinit var binding: ActivitySettingBinding
private var interstitialAd: InterstitialAd? = null

override fun onCreate(savedInstanceState: Bundle?) {
MobileAds.initialize(this) {}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.statusBarColor = ContextCompat.getColor(this, R.color.lightgrey)
}
binding= ActivitySettingBinding.inflate(layoutInflater)
super.onCreate(savedInstanceState)
setContentView(binding.root)
loadAd()
//        loadInterstitial()

binding.shareTv.setOnClickListener {
val intent= Intent().apply{
type = "text/plain"
action = Intent.ACTION_SEND
}
startActivity(intent)
}

binding.feedbackTv.setOnClickListener {

val recipient = "[email protected]"
val subject = "App Feedback"
val body = "I want to share my thoughts on your app..."

val uriString = String.format("mailto:%s?subject=%s&body=%s",
Uri.encode(recipient),
Uri.encode(subject),
Uri.encode(body)
)
val uri = Uri.parse(uriString)

val emailIntent = Intent(Intent.ACTION_SENDTO, uri).apply {
setPackage("com.google.android.gm")
}
startActivity(emailIntent)
}

binding.rateTv.setOnClickListener {
RateAppDialog.show(this)
}

binding.adbtn.setOnClickListener {
//            showAd()
if (interstitialAd != null) {
interstitialAd?.show(this)
} else {
showAd()  // fallback if ad is not ready
}
}

}
//    private fun loadInterstitial() {
//        val adRequest = AdRequest.Builder().build()
//        InterstitialAd.load(
//            this,
//            "ca-app-pub-3940256099942544/1033173712",  // replace with real ad unit ID
//            adRequest,
//            object : InterstitialAdLoadCallback() {
//                override fun onAdLoaded(ad: InterstitialAd) {
//                    interstitialAd = ad
//                    setAdCallbacks()
//                }
//
//                override fun onAdFailedToLoad(error: LoadAdError) {
//                    interstitialAd = null
//                }
//            }
//        )
//    }
//
//    private fun setAdCallbacks() {
//        interstitialAd?.fullScreenContentCallback = object : FullScreenContentCallback() {
//            override fun onAdDismissedFullScreenContent() {
//                interstitialAd = null
//                loadInterstitial() // preload next ad
//                doAction()
//            }
//        }
//    }
//
//    private fun doAction() {
//        Toast.makeText(this, "Button action executed", Toast.LENGTH_SHORT).show()
//        // your actual button logic here
//    }

private fun showAd() {
if (interstitialAd != null) {
interstitialAd?.show(this)
Log.d("TAG", "Ad displayed. Loading next ad.")
// After showing an ad, it can't be reused.  Load a new one immediately.
loadAd()
} else {
Log.d("TAG", "Interstitial ad is not ready yet.")
// Optional: You can try to load an ad again if it's not ready
// loadAd()
}
}

private fun loadAd(){
val adRequest = AdRequest.Builder().build()
InterstitialAd.load(this, "ca-app-pub-3940256099942544/1033173712", adRequest, object : InterstitialAdLoadCallback() {
override fun onAdFailedToLoad(adError: LoadAdError) {
interstitialAd = null
}

override fun onAdLoaded(ad: InterstitialAd) {
interstitialAd = ad
}
})
}
}

Hier ist meine Manifestdatei, die alle erforderlichen Tags enthält, aber die Anzeige zeigt immer noch nicht an, was das Problem sein könnte

Code: Select all



















```

the below are my dependency for app level build.gradle file
```    implementation("androidx.datastore:datastore-preferences:1.2.0")
implementation(platform("com.google.firebase:firebase-bom:33.1.0"))

implementation("com.google.firebase:firebase-config-ktx")
implementation("com.google.firebase:firebase-analytics:21.6.2")

implementation("com.google.android.gms:play-services-ads:24.8.0")

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post