diff --git a/gma/src/android/native_ad_image_android.cc b/gma/src/android/native_ad_image_android.cc index 8c63c9b244..23af8c4fb2 100644 --- a/gma/src/android/native_ad_image_android.cc +++ b/gma/src/android/native_ad_image_android.cc @@ -71,6 +71,15 @@ NativeAdImage::NativeAdImage( FIREBASE_ASSERT(j_uri); internal_->uri = util::JniUriToString(env, j_uri); + // Images requested with an android user agent may return webp images. Trim + // webp parameter from image url to get the original JPG/PNG image. + std::size_t eq_pos = internal_->uri.rfind("="); + std::size_t webp_pos = internal_->uri.rfind("-rw"); + if (webp_pos != std::string::npos && eq_pos != std::string::npos && + webp_pos > eq_pos) { + internal_->uri.replace(webp_pos, 3, ""); + } + // NativeAdImage scale. jdouble j_scale = env->CallDoubleMethod(internal_->native_ad_image,