Quando il caricamento di un annuncio non va a buon fine, è sempre presente un
callback
il cui scopo è fornire un
LoadAdError
oggetto.
Per an AdView
, si chiama:
Java
public void onAdFailedToLoad(LoadAdError adError);
Kotlin
fun onAdFailedToLoad(error: LoadAdError)
Ecco uno snippet di codice che illustra le informazioni disponibili quando un annuncio non viene caricato:
Java
@Override public void onAdFailedToLoad(LoadAdError error) { // Gets the domain from which the error came. String errorDomain = error.getDomain(); // Gets the error code. See // https://developers.google.com/android/reference/com/google/android/gms/ads/AdRequest#constant-summary // for a list of possible codes. int errorCode = error.getCode(); // Gets an error message. // For example "Account not approved yet". See // https://support.google.com/admob/answer/9905175 for explanations of // common errors. String errorMessage = error.getMessage(); // Gets additional response information about the request. See // https://developers.google.com/admob/android/response-info for more // information. ResponseInfo responseInfo = error.getResponseInfo(); // Gets the cause of the error, if available. AdError cause = error.getCause(); // All of this information is available via the error's toString() method. Log.d("Ads", error.toString()); }
Kotlin
override fun onAdFailedToLoad(error: LoadAdError) { // Gets the domain from which the error came. val errorDomain = error.domain // Gets the error code. See // https://developers.google.com/android/reference/com/google/android/gms/ads/AdRequest#constant-summary // for a list of possible codes. val errorCode = error.code // Gets an error message. // For example "Account not approved yet". See // https://support.google.com/admob/answer/9905175 for explanations of // common errors. val errorMessage = error.message // Gets additional response information about the request. See // https://developers.google.com/admob/android/response-info for more // information. val responseInfo = error.responseInfo // Gets the cause of the error, if available. val cause = error.cause // All of this information is available via the error's toString() method. Log.d("Ads", error.toString()) }
Queste informazioni possono essere utilizzate per determinare con maggiore precisione la causa del mancato caricamento del annuncio.
In particolare, per quanto riguarda gli errori relativi al dominio
MobileAds.ERROR_DOMAIN
,
il messaggio
puoi cercare in questo articolo del Centro assistenza una spiegazione più dettagliata e le possibili azioni da intraprendere per risolvere il problema.