This document facilitates the integration of Mediation Layer Android SDK. There are four integration types for developers:
For more detailed documentation, please refer to our github documentation (linked above).
Integration samples project
Here you can find a collection of most common pubnative SDK integration examples for Android.
Requirements
- Android API 15 or greater
- An App Token provided in PubNative Dashboard.
- A Placement Name configured in the PubNative Dashboard.
Permissions
Add the following permissions to your application manifest file.
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
Optionally but necessary for better tracking, you can add one of them or both location permisssion
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
or
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Note: If you are using both NETWORK_PROVIDER and GPS_PROVIDER, then you need to request only the ACCESS_FINE_LOCATION permission, because it includes permission for both providers. (Permission for ACCESS_COARSE_LOCATION includes permission only for NETWORK_PROVIDER).
Install Pubnative SDK
Gradle
The PubNative Mediation SDK is available via jCenter. To add the sdk dependency, open your project's build.gradle and update the repositories and dependencies blocks as follows:
repositories {
// ... other project repositories
jcenter()
}
// ...
dependencies {
// ... other project dependencies
compile 'net.pubnative:sdk:2.0.12'
}
Jar
Download jar from here and add it into your app.
How to add jar in Android studio
- Copy the jar file from where you downloaded it.
- paste it in
libs
folder. - open build.gradle.
- add lines under dependencies as:
compile fileTree(dir: 'libs', include: ['*.jar'])
Manual
Clone the repository and import the :sdk
project into your app.
ProGuard
Obfuscation protects an application from reverse-engineering or modification by making it harder for a third-party to access your source (decompiled) code.
PubNative SDK is already obfuscated Therefore, if you did not obfuscate your application using ProGuard™
, then you can skip this step. If you have obfuscated your application using ProGuard, then you need to add these lines in the ProGuard configuration file:
-keepattributes Signature
-keep class net.pubnative.** { *; }
Configure SDK
There are certain parameters that should be configured in the SDK before doing any type of interaction with It. Ensure to configure this parameters only 1 per session.
If you are doing tests:
Pubnative.setTestMode(boolean);
If your app is COPPA compliant:
Pubnative.setCoppaMode(boolean);
If you want to improve targeting, first configure the PNAdTargetingModel object that you want to give away and then invoke the following method:
Pubnative.setTargeting(PNAdTargetingModel);
Initialise SDK
In order to initialise request you must call init() before requesting for ads.
Pubnative.init(<CONTEXT>, "<YOUR_APP_TOKEN_HERE>");