Lỗi khi tải quảng cáo

Khi một quảng cáo không tải được, hệ thống luôn gọi lại được gọi để cung cấp đối tượngLoadAdError .

Đối với an AdView, lệnh gọi lại là:

Dưới đây là một đoạn mã minh họa thông tin có sẵn khi quảng cáo không tải được:

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())
}

Bạn có thể sử dụng thông tin này để xác định chính xác hơn nguyên nhân khiến quảng cáo không tải được. Cụ thể, đối với các lỗi trong miền MobileAds.ERROR_DOMAIN, thông báo có thể được tra cứu trong bài viết này trong trung tâm trợ giúp để biết thông tin giải thích chi tiết hơn và những việc bạn có thể làm để giải quyết vấn đề.