На 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
Почему реклама не загружается, когда приложение впервые запускается на Android 13+? ⇐ Android
Форум для тех, кто программирует под Android
1746270204
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?
Подробнее здесь: [url]https://stackoverflow.com/questions/79604528/why-ads-dont-load-when-the-app-is-first-launched-on-android-13[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия