Integrating the Mobile Ads SDK
This is an archived version of the documentation. Actual documentation for all platforms can be found here.
- To load ads of any type, Android 4.1 or later is required.
- Video ads are only selected for devices with Android 5.0 or later.
The Yandex Mobile Ads library is provided in AAR format. To enable the Mobile Ads SDK:
Add the Yandex Mobile Ads dependency to the build.gradle file of your app's module:
dependencies { ... implementation 'com.yandex.android:mobileads:5.10.0' }
Update the kotlin-gradle-plugin dependency in your project's root build.gradle file:
dependencies { ... classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10") }
Add Java 8 support to the build.gradle file in your app's module:
android { compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } }
Set up permission to use the ad ID.
The ad ID is a unique identifier provided by Google Play services for displaying ads to users who opt in to personalized ads. Users can opt out of ad personalization or reset their ID in the settings. In this case, advertising networks won't be able to use the ID to select relevant ads for the user.
A new permission has been made available in the Yandex Mobile Ads SDK version 4.5.0 and higher:
com.google.android.gms.permission.AD_ID
. It's written in the library's AndroidManifest.xml file. Because of this, you don't have to specify it in the application's main manifest. The permission allows you to use an ad ID to select relevant ads from advertising networks.You can delete the permission if necessary. For example, if a policy does not allow the use of an ID for ad selection, such as the Families Policy.
To prevent the permission from being added to the application's main manifest, add the following line to AndroidManifest.xml:
<uses-permission android:name="com.google.android.gms.permission.AD_ID" tools:node="remove"/>
If your app uses a version of the Yandex Mobile Ads SDK below 4.5.0 and there are no restrictions on the use of an ad ID (for example, Families Policy), add the permission to the application's main manifest AndroidManifest.xml:
<uses-permission android:name="com.google.android.gms.permission.AD_ID"/>
Lack of this permission and access to the ID may reduce the relevance of ads and, as a result, your income.
Initializing the Mobile Ads SDK
Before loading ads, initialize the library using the initialize() method. Initialization makes ads load faster.
It's needed each time the app starts. That's why we recommend that you add the initialization code to the onCreate
method of the Application
class.
- Initialization example:
-
public class YandexApplication extends Application { private static final String YANDEX_MOBILE_ADS_TAG = "YandexMobileAds"; @Override public void onCreate() { super.onCreate(); MobileAds.initialize(this, new InitializationListener() { @Override public void onInitializationCompleted() { Log.d(YANDEX_MOBILE_ADS_TAG, "SDK initialized"); } }); } }
See the SDK usage examples.