Getting started on Android
This page explains how to install the Smart Instream SDK into an Android application. This is the first step to complete before delivering instream ads in your video content.
Prerequisites
There are some prerequisites to use the instream SDK:
- You need to use Android Studio 3.0 or higher
- For phone apps, you need to target at least Android 4.4 (API level 19) or higher
- For TV apps, you need to target at least Android 5.0 (API level 21) or higher
- AndroidX migrated application (starting from 7.7.0 Smart Instream SDK version)) .
Advertising ID
The Smart Instream SDK uses the Google Advertising ID of the device, 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 Instream 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 Instream 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 Instream SDK artifact dependency and the optional Huawei support library:dependencies { // … // Add Smart Instream SDK implementation 'com.smartadserver.android:smart-instream-sdk:7.26.0' // Optional : add Smart support library for Huawei devices implementation 'com.smartadserver.android:smart-core-sdk-huawei-support:1.0.0' }
All dependencies needed by the Smart Instream SDK will be automatically imported by Gradle.
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. -
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 by following the integration guide.
Location
For ad targeting purposes, the Smart Instream SDK can automatically send the latest known user location, if already made available to the application (The Smart Instream 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);
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 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>