Setting up your app

Minimum requirements

First, check out if you fulfill the SDK minimum requirements.
Requirement
Version
Minimum Android SDK version
Android API 16
Android Support Library v4
28+
Google Play Services Ads
12.+
Google Play Services Location
12.+
If your project is using AndroidX you will need to make sure Jetifier is enabled in your gradle.properties file:
gradle.properties
1
android.useAndroidX=trueandroid.enableJetifier=true
Copied!

Dependencies

In your app-level build.gradle file, add the following dependencies.
Android X
Android Support
1
dependencies {
2
// Required
3
implementation 'com.inlocomedia.android:android-sdk-ads:5.4.1'
4
implementation 'com.inlocomedia.android:android-sdk-engagement:5.4.1'
5
6
// Google Play Services
7
implementation 'com.google.android.gms:play-services-location:17.0.0'
8
implementation 'com.google.android.gms:play-services-ads-identifier:17.0.0'
9
​
10
// Compatibility with Support Library
11
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
12
}
Copied!
1
dependencies {
2
// Required
3
implementation 'com.inlocomedia.android:android-sdk-ads:5.4.1'
4
implementation 'com.inlocomedia.android:android-sdk-location:5.4.1'
5
6
// Google Play Services
7
implementation 'com.google.android.gms:play-services-location:16.0.0' // You can use versions from 12.0.0 up to 16.0.0
8
implementation 'com.google.android.gms:play-services-ads-identifier:16.0.0' // You can use versions from 12.0.0 up to 16.0.0
9
​
10
// Support Library
11
implementation 'com.android.support:support-v4:28.0.0'
12
}
Copied!
After updating your app-level build.gradle, the project must be synced for the changes to take effect

Update Android manifest

Add the following <uses-permission> tags inside the <manifest> tag of your AndroidManifest.xml file.
AndroidManifest.xml
1
<manifest>
2
<!-- Required for connectivity access -->
3
<uses-permission android:name="android.permission.INTERNET" />
4
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
5
6
<!-- Required for location services -->
7
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
8
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
9
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
10
11
<!-- Improves location accuracy and battery consumption -->
12
<uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION"/>
13
14
<!-- Allows the SDK to restart itself after the device is rebooted -->
15
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
16
17
<!-- For apps targeting Android 10 (29) and higher only -->
18
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION"/>
19
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>
20
</manifest>
Copied!
If you want, take a look at why we ask these permissions:

Add config file to your project

The Inloco SDK initialization relies on the presence of an inloco.xml file in the main/res/values directory of your project.
Please modify the inloco_app_id field and add it to the main/res/values directory in your Android project.
inloco.xml
1
<?xml version="1.0" encoding="utf-8"?>
2
<resources>
3
<!-- Your In Loco App id-->
4
<string name="inloco_app_id" translatable="false">YOUR_APP_ID</string>
5
​
6
<!-- Whether SDK logs are enabled -->
7
<bool name="inloco_log_enabled">true</bool>
8
​
9
<!-- Whether the user needs to provide privacy consent -->
10
<bool name="inloco_privacy_consent_required">false</bool>
11
​
12
<!-- Development devices -->
13
<array name="inloco_development_devices">
14
<item>SAMPLE_DEVELOPMENT_DEVICE_ID_1</item>
15
<item>SAMPLE_DEVELOPMENT_DEVICE_ID_2</item>
16
</array>
17
</resources>
Copied!
​
🧠
Note: Remember to replace OUR_APP_IDwith the identifier of the application you created on your dashboard. Click here if you don't know your App ID or if you don't know what App ID is.
The complete list of possible customization keys is shown below.
Key
Description
Type
Required
inloco_app_id
Your Application ID.
string
​
βœ”
inloco_log_enabled
Whether logs are enabled.
boolean (true)
​
βœ–
​
inloco_visits_enabled_by_default
Whether visit tracking is enabled by default during the SDK initialization.
boolean (true)
​
βœ–
inloco_privacy_consent_required
Whether the user needs to provide privacy consent for the SDK to be initialized.
boolean (false)
​
βœ–
inloco_background_wakeup_enabled
Whether background wakeup is enabled.
boolean (true)
​
βœ–
inloco_development_devices
The devices that will receive only testing ads.
string array
​
βœ–
​

​
πŸš€
Initializing the SDK

Inside the onCreate method of your Application class, insert the following code to initialize the Inloco SDK.
Kotlin
Java
Old Version v4.0
1
import com.inlocomedia.android.common.InLoco
2
​
3
class CustomApplication : Application() {
4
5
override fun onCreate() {
6
super.onCreate()
7
8
//Initializes the InlocoMedia SDK
9
InLocoMedia.init(this)
10
}
11
}
Copied!
1
import com.inlocomedia.android.common.InLoco;
2
​
3
public class CustomApplication extends Application {
4
​
5
@Override
6
public void onCreate() {
7
super.onCreate();
8
​
9
//Initializes the InlocoMedia SDK
10
InLoco.init(this);
11
}
12
}
Copied!
1
public class CustomApplication extends Application {
2
​
3
@Override
4
public void onCreate() {
5
super.onCreate();
6
​
7
// In Loco Media SDK Init
8
InLocoMediaOptions options = InLocoMediaOptions.getInstance(this);
9
​
10
// The AppId you acquired in earlier steps
11
options.setAdsKey("YOUR_APP_ID");
12
​
13
// Verbose mode flag, if this is set as true InLocoMedia SDK will let you know about errors on the Logcat
14
options.setLogEnabled(true);
15
​
16
// Development Devices set here are only going to receive test ads
17
options.setDevelopmentDevices("Devices_ids");
18
​
19
//Initializes the InlocoMedia SDK
20
InLocoMedia.init(this, options);
21
}
22
}
Copied!
​
πŸ§™
Tips: For instructions on how to create your own implementation of the Application class, please check the official Android documentation.
If the SDK was initialized properly, your Logcat
😺
output will contain the following logs.
Logcat
1
I/InLocoMedia: In Loco 5.4.1 is running
2
I/InLocoMedia: In Loco Ads SDK 5.4.1 is running
3
I/InLocoMedia: In Loco Location SDK 5.4.1 is running
4
I/InLocoMedia: To get test ads on this device, add "<Your device Id>" as a development device ID on inLocoOptions
Copied!

​
πŸ”§
Testing

Copy the value of "Your_Device_ID" in the log shown above and paste it as the parameter of the inloco_development_devices property in your inloco.xml file. This will ensure that this device only receives testing Ads.
inloco.xml
Old Version v4.0
1
//...other properties
2
​
3
<array name="inloco_development_devices">
4
<item><Your device Id></item>
5
</array>
Copied!
1
import com.inlocomedia.android.common.InLoco;
2
​
3
public class CustomApplication extends Application {
4
​
5
@Override
6
public void onCreate() {
7
super.onCreate();
8
​
9
// In Loco Media SDK Init
10
InLocoMediaOptions options = [...]
11
​
12
// Development Devices set here are only going to receive test ads
13
options.setDevelopmentDevices("<Your Device Id>");
14
​
15
//Initializes the InlocoMedia SDK
16
InLocoMedia.init(this, options);
17
}
18
}
Copied!
Any errors in the steps above will be shown in your log, under the tag β€œInLocoMedia”.

Testing your first Ad

Let’s implement an Interstitial Ad to make sure the integration is working correctly.
  • Insert the code below in any activity to test the integration;
  • Run the application and open the activity that contains the ad;
java
1
import com.inlocomedia.android.ads.interstitial.*;
2
import com.inlocomedia.android.ads.AdError;
3
import com.inlocomedia.android.ads.AdRequest;
4
​
5
public class YourActivity extends Activity {
6
​
7
@Override
8
protected void onCreate(Bundle savedInstanceState) {
9
super.onCreate(savedInstanceState);
10
​
11
InterstitialAd interstitialAd = new InterstitialAd(getApplicationContext());
12
interstitialAd.setInterstitialAdListener(new InterstitialAdListener() {
13
​
14
@Override
15
public void onAdReady(final InterstitialAd ad) {
16
ad.show();
17
}
18
​
19
@Override
20
public void onAdError(InterstitialAd ad, AdError error) {
21
Log.w("InLocoMedia", "Your interstitial has failed with error: " + error);
22
}
23
});
24
​
25
AdRequest adRequest = new AdRequest();
26
interstitialAd.loadAd(adRequest);
27
}
28
}
Copied!
Make sure that Internet is available.
You will see the Interstitial ad on your screen, and it will indicate the integration was successful. You can now remove the code above and proceed to create the ads you will use on your application by following the next steps.

​
πŸšΆβ™‚
Request runtime permissions

The previous step started the Inloco SDK, but your application still needs to request the location permissions (i.e., ACCESS_FINE_LOCATION and ACCESS_BACKGROUND_LOCATION) to the user in order to fully unlock the location capabilities of the SDK.
We recommend that the permissions are requested as shown in the Android documentation.
​
🚧
Attention: Without the Manifest.permission.ACCESS_FINE_LOCATION, location-based ads will not be available. It is extremely important that the user is asked for permission and that the app has a relevant reason to do so. If you are targeting Android 10, you also must ask for Manifest.permission.ACCESS_BACKGROUND_LOCATION.
Last modified 1yr ago