Getting started on Android
This page explains how to install the Smart Display SDK into an Android application. This is the first step to complete before delivering ads in your application.
Prerequisites
There are some prerequisites prior to integrating the Smart Display SDK in your application:
- Android Studio 3.0 or higher.
- Android 4.4 (API level 19) or higher.
- AndroidX migrated application (starting from 7.8.0 Smart Display SDK version)) .
Advertising ID
The Smart Display SDK uses the Google Advertising ID of the device (if available), which will be sent during ad calls. You should always comply with your local laws, check the Privacy laws compliancy page for more details.
The Google Advertising ID might be unavailable on some devices, either because the user has opted-out in the device settings or because the device does not implement the Google Play Services. When the Google Advertising ID is not available, the SDK will not send any advertising ID.
Installation via Gradle
To import the Smart Display SDK into your Android project, here are the steps to follow:
-
In the main
build.gradle
of your project, you must declare the repository where the Smart Display SDK is hosted.
If you intend to support Huawei devices that do not feature Google services anymore (needed for Advertising Id retrieval), you also need to declare the Huawei support libraries repository:allprojects { repositories { google() jcenter() // add the Smart repository maven { url 'https://packagecloud.io/smartadserver/android/maven2' } // Optional: Huawei services dependencies repository maven { url 'https://developer.huawei.com/repo/' } // … } }
If you do not plan on supporting Huawei devices and their specific Advertising Id (counterpart of Google's Advertising Id), you can omit to declare the Huawei repository. Note that Advertising Id will be missing on Huawei devices, hence disabling all kinds of targeting options that require device identification. -
In the
dependencies
section of your application modulebuild.gradle
file, declare the Smart Display SDK artifact dependency and the optional Huawei support library:dependencies { // … // Add Smart Display SDK implementation 'com.smartadserver.android:smart-display-sdk:7.25.1' // Optional : add Smart support library for Huawei devices implementation 'com.smartadserver.android:smart-core-sdk-huawei-support:2.0.0' }
All dependencies needed by the Smart Display SDK will be automatically imported by Gradle.
Note that Smart Display SDK will import ExoPlayer 2.15.1 and okhttp 4.9.0. Forcing an Exoplayer library version of 2.14.x and below is likely to cause crashes.Reminder from above paragraph: if you do not plan on supporting Huawei devices and their specific Advertising Id (counterpart of Google's Advertising Id), you can omit to declare the Huawei dependency. Note that Advertising Id will be missing on Huawei devices, hence disabling all kinds of targeting options that require device identification.If you want to enable mediation for Smart Display SDK as primary SDK, please go to the Integrate adapters page. -
In the
android
section of your application modulebuild.gradle
file, add the Java 8 compile options needed by some imported libraries:android { // … compileOptions { targetCompatibility = JavaVersion.VERSION_1_8 sourceCompatibility = JavaVersion.VERSION_1_8 } }
-
You can now proceed with the integration of your ads directly within your project's workspace.
You can start by integrating a banner ad, an interstitial, a rewarded video or a native ad
Location
For ad targeting purposes, the Smart Display SDK can automatically send the latest known user location, if already made available to the application (The Smart Display SDK will never actively try to retrieve user location).This automatic location retrieval is disabled by default, and you can enable as follows, provided that one of the location permissions is granted to the application, and that the User consent was properly collected for ad targeting purpose regarding his location.
SASConfiguration.getSharedInstance().setAutomaticLocationAllowed(true);
SASConfiguration.getSharedInstance().isAutomaticLocationAllowed = true;
Network Security Configuration
Since Android 9 (API level 28), the default network security configuration is not as lenient as it was on previous versions: all network requests must use HTTPS protocol, basic HTTP requests will be blocked by default.
Even though the ad industry progresses towards full HTTPS support, it might happen that some medias are not hosted on secured servers. To avoid your ads being blocked by the default network security configuration, you should create your own network security configuration XML file.
In your res
folder, create the folder xml
(if not created yet) then inside that folder create a file named network_security_configuration.xml
.
Your file must be formatted like this (note: this was the default network security configuration for Android 6.0 (API level 23)):
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config>
<trust-anchors>
<certificates src="system" />
<certificates src="user" />
</trust-anchors>
</base-config>
</network-security-config>
Once the file created, make sure to add android:networkSecurityConfig="@xml/network_security_config"
in the application
tag of your AndroidManifest.xml
file. For instance:
<application
android:name=".MyApplication"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:networkSecurityConfig="@xml/network_security_config">
</application>