Почему реклама не загружается, когда приложение впервые запускается на Android 13+?Android

Форум для тех, кто программирует под Android
Ответить
Anonymous
 Почему реклама не загружается, когда приложение впервые запускается на Android 13+?

Сообщение Anonymous »

На Android 13+, первая нагрузка на объявление объявляет ошибку без заполнения в onAdfailedToLoad (). AD_ID добавлен в Manifest < /p>

< /code>
Сам код прост: < /p>
fun load(
context: Context,
adUnitId: String,
screenAdsId: String,
callback: (InterstitialAd?) -> Unit
) {
val adRequest = AdRequest.Builder().build()
InterstitialAd.load(
context,
adUnitId,
adRequest,
object : InterstitialAdLoadCallback() {
override fun onAdLoaded(ad: InterstitialAd) {
Log.i("mLogAds", "$screenAdsId onAdLoaded")
callback(ad)
}

override fun onAdFailedToLoad(adError: LoadAdError) {
Log.e("mLogAds", "$screenAdsId onAdFailedToLoad: $adError ${adError.code} ${adError.message}")
}
}
}
< /code>
fun show(
interstitialAd: InterstitialAd?,
context: Context,
screenAdsId: String,
onAdClosed: () -> Unit
) {
interstitialAd?.let { ad ->
ad.fullScreenContentCallback = object : FullScreenContentCallback() {
override fun onAdDismissedFullScreenContent() {
Log.i("mLogAds", "$screenAdsId onAdDismissedFullScreenContent")
onAdClosed()
}

override fun onAdFailedToShowFullScreenContent(adError: AdError) {
Log.e("mLogAds", "$screenAdsId onAdFailedToShowFullScreenContent: $adError")
onAdClosed()
}

override fun onAdShowedFullScreenContent() {
Log.i("mLogAds", "$screenAdsId onAdShowedFullScreenContent")
}
}
ad.show(context as androidx.activity.ComponentActivity)
} ?: onAdClosed()
}
}
< /code>
I also check Consent before starting initialization:
consentInformation.requestConsentInfoUpdate(this, params, {
if (consentInformation.isConsentFormAvailable) {
UserMessagingPlatform.loadAndShowConsentFormIfRequired(this) { formError ->
Log.i("mLogAdsTest", "CONSENT SUCCESS")
viewModel.updateInitState(true)
if (consentInformation.canRequestAds()) {
Log.d("mLogAdsTest", "googleMobileAdsConsentManager.canRequestAds")
initializeMobileAdsSdk()
}
}
} else {
if (consentInformation.canRequestAds()) {
initializeMobileAdsSdk()
}
}
< /code>
And only if everything is initialized I start the download:
private fun initializeMobileAdsSdk() {
val coroutineExceptionHandler = CoroutineExceptionHandler { _, throwable ->
println(throwable.message)
}
val backgroundScope = CoroutineScope(Dispatchers.Main + coroutineExceptionHandler)
MobileAds.setRequestConfiguration(
RequestConfiguration.Builder()
// .setTestDeviceIds(listOf(TEST_DEVICE_HASHED_ID))
.build()
)
backgroundScope.launch {
MobileAds.initialize(this@MainActivity) {
Log.e("mLogAdsTest", "INIT")
it.adapterStatusMap.forEach { s, adapterStatus ->
if (adapterStatus.initializationState.toString() == "READY") {
Log.i("mLogAdsTest", "READY")
viewModel.updateInitState(true)
}
}
}
}
}

< /code>
CoroutineScope also installed IO, the result is the same
After that I start loading ads:
viewModel.updateInitState(true)
< /code>
I also tried to build a very simple project with only loading and show, without all the extra stuff, it didn't help.
Moving MobileAds.initialize(this) to the Application class also doesn't work.
Re-loading in onAdFailedToLoad() simply gives the same result, the ad doesn't load throughout the first launch no matter how much you try, but from the second everything is fine. And this applies not only to interstitial.
I tried library versions 23.6.0 and 24.0.0, 24.0.1, 24.0.2, all the same.
I also get the same result even in the example project from Google itself.
Has anyone else encountered something similar, is something wrong with my code or is it a problem on Google's part?
And what can be done?

Подробнее здесь: https://stackoverflow.com/questions/796 ... android-13
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Android»