Monday, July 18, 2022

Use the new Google Mobile Ads SDK getVersion() method

We heard your feedback that MobileAds.getVersionString() was confusing as it didn’t match the external version. We addressed it by adding a new method - MobileAds.getVersion(). In doing so, we have deprecated MobileAds.getVersionString().

Distinctions between getVersionString() and getVersion()

getVersionString() [deprecated] getVersion()
Sample return value afma-sdk-a-v214106000.214106000.0 21.0.0
Requires calling initialize() first? Yes No

Calling MobileAds.getVersionString() returns an internal version number. The MobileAds.getVersion() method outputs a simplified, external version number that matches the version in the release notes. For example, 21.0.0.

Also as part of the v21.0.0 release, you can call MobileAds.getVersion() before calling MobileAds.initialize(). Previously, you had to initialize the SDK to query the SDK version number, or else the app would crash.

Querying the SDK version number can be accomplished in your Android apps with the following code snippet:

// Log the Mobile Ads SDK Version.
Log.d("MyApp", MobileAds.getVersion()); // "21.0.0"

// Initialize the SDK.
MobileAds.initialize(this, new OnInitializationCompleteListener() {
    @Override
    public void onInitializationComplete(InitializationStatus status) {} 
});

For the full list of changes in the v21.0.0 release, check the release notes. If you have any questions or need additional help, contact us via the forum.