You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过代码获取Android端Google Ads SDK(AdMob)版本?

How to Retrieve Google Ads AdMob SDK Version on Android (Matching iOS's [GADRequest sdkVersion])

Got it, I totally get wanting to replicate that handy iOS SDK version check on Android—luckily there are a couple straightforward ways to do this, especially for your 17.1.1 SDK version:

Google provides a dedicated method to fetch the SDK version directly, which mirrors iOS's [GADRequest sdkVersion] perfectly. Just use the MobileAds.getVersion() method:

// Make sure to import the required class first
import com.google.android.gms.ads.MobileAds;

// Fetch the version string
String adSdkVersion = MobileAds.getVersion();
// This will return exactly the version you declared in Gradle, like "17.1.1"

This method is clean, purpose-built for this use case, and fully supported in the 17.1.1 version of the AdMob SDK you’re using.

Method 2: Fetch via Package Manager (Fallback for Older SDKs)

If you ever need to support older SDK versions where MobileAds.getVersion() isn’t available, you can pull the version from the SDK’s package info:

try {
    // Get package info for the AdMob SDK's underlying package
    PackageInfo packageInfo = getPackageManager().getPackageInfo("com.google.android.gms.ads", 0);
    String adSdkVersion = packageInfo.versionName;
} catch (PackageManager.NameNotFoundException e) {
    // Handle the rare case where the package isn't found (unlikely if you have the SDK added)
    e.printStackTrace();
}

This works by accessing the version name of the AdMob SDK’s Android package, which matches the version you specified in your Gradle dependency.

内容的提问来源于stack exchange,提问作者user2679041

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 06:23:37