Quickstart
Follow these steps to have a basic integration of the app's miles® SDK in your Android application.
Android Quickstart

Estimated time: 20 minutes
This guide will go over:
- Conditions and minimum requirements
- Installation📦
- Configuration⚙
- Initialization⚡
- Attaching🔗
Minimum Android version: 4.1 (API 16)
This guide was written under the assumption that you use Android Studio
Add the following lines to your top-level
build.gradle
file.root/build.gradle
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
//You can set login and password in env variables
def mavenAppsmilesUsername = System.getenv("APPSMILES_ARTIFACTORY_LOGIN") ?: ''
def mavenAppsmilesPassword = System.getenv("APPSMILES_ARTIFACTORY_PASSWORD") ?: ''
//Or in local.properties
def folder = new File( 'local.properties' )
if( folder.exists() ) {
properties.load(project.rootProject.file('local.properties').newDataInputStream())
mavenAppsmilesUsername = properties.getProperty("maven_appsmiles.username") ?: mavenAppsmilesUsername
mavenAppsmilesPassword = properties.getProperty("maven_appsmiles.password") ?: mavenAppsmilesPassword
}
allprojects {
repositories {
//...
maven {
url 'https://artifactory.appsmiles.eu/artifactory/list/appsmiles/'
credentials {
username = mavenAppsmilesUsername
password = mavenAppsmilesPassword
}
}
}
}
https://artifactory.appsmiles.eu/artifactory/list/appsmiles is a private repository, you need a login and a password
Set the login and password in the file local.properties of your project
Contact us to get a login and password
And these to your app's
build.gradle
fileroot/app/build.gradle
dependencies {
//...
implementation 'com.moonmiles.apm:apm:6.3.1'
//...
}
The weight of an android application containing our SDK will approximately increase by 2.5 MB
Our SDK uses the dependencies appcompat, recyclerview and lottie to work.
You can overwrite them in your module's build.gradle:
build.gradle
dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'com.airbnb.android:lottie:3.5.0'
}
For security reasons, our server only supports HTTPS connection with TLS 1.2 protocol.
However, Android 4.1 – 4.4 phones don't use TLS 1.2 out-of-the-box, and need the help of Google Play Services.
In order to fix this, we need the play-services-base library. It is already included in all of the play-services-* libraries, so:
- otherwise, you need to add this dependency:
implementation 'com.google.android.gms:play-services-base:16.1.0'
More informations here : https://developer.android.com/training/articles/security-gms-provider.html
Set (1) the permissions in your AndroidManifest.xml
AndroidManifest.xml
<manifest ...>
...
<!-- (1) Permissions -->
<!-- required -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- optional -->
<uses-permission android:name="android.permission.VIBRATE"/>
...
</manifest>
Add the following lines for ProGuard
proguard-rules.pro
# app's miles
-keep class com.moonmiles.** { *; }
-keep interface com.moonmiles.** { *; }
In YourAppApplication.java, in the method onCreate(), retrieve an instance of APM and init the SDK with your credentials environments
MyApplication.java
@Override
public void onCreate() {
super.onCreate();
String partnerId = getResources().getString(R.string.ConfigPartnerID);
String partnerSecret = getResources().getString(R.string.ConfigPartnerSecret);
String appId = getPackageName();
String baseUrl = getResources().getString(R.string.ConfigBaseUrl);
//Init SDK APM
APM apm = APM.sharedInstance(this); //this == Context
apm.initApp(partnerId, partnerSecret, appId);
apm.setBaseUrl(baseUrl);
}
You can declare multiple environments using the application's packageName or you can specifically declare environments with the appId variable.
MyApplication.java
@Override
public void onCreate() {
super.onCreate();
String partnerId = getResources().getString(R.string.ConfigPartnerID);
String partnerSecret = getResources().getString(R.string.ConfigPartnerSecret);
String appId;
String baseUrl;
if(SANDBOX) {
appId = "com.your_company.your_app_sandbox";
baseUrl = "https://api-sb.appsmiles.eu/";
}
else {
appId = "com.your_company.your_app";
baseUrl = "https://api-prod1.appsmiles.eu/"
}
//Init SDK APM
APM apm = APM.sharedInstance(this); //this == Context
apm.initApp(partnerId, partnerSecret, appId);
apm.setBaseUrl(baseUrl);
}
Environment | URL |
PRODUCTION | https://api-prod1.appsmiles.eu/ |
SANDBOX | https://api-sb.appsmiles.eu/ |
We host projects on multiple servers, double check with us or your team to verify the base URL.
For this last step, you must attach our SDK to your GlobalActivity and GlobalFragment
Automatically
Manually
You can extend your GlobalActivity with APMClientAppCompatActivity or APMClientFragmentActivity
public class GlobalActivity extends APMClientAppCompatActivity
//OR
public class GlobalActivity extends APMClientFragmentActivity
Add the following methods in your GlobalActivity
onCreate(Activity activity);
onResume(Activity activity);
onPause(Activity activity);
onDestroy(Activity activity);
onNewIntent(Activity activity, Intent intent);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
APMClientActivityUtils.onCreate(this);
}
@Override
protected void onResume() {
super.onResume();
APMClientActivityUtils.onResume(this);
}
@Override
protected void onPause() {
super.onPause();
APMClientActivityUtils.onPause(this);
}
@Override
protected void onDestroy() {
super.onDestroy();
APMClientActivityUtils.onDestroy(this);
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
APMClientActivityUtils.onNewIntent(this, intent);
}
Automatically
Manually
You can extend your GlobalFragment with APMClientFragment or APMClientDialogFragment
public class GlobalFragment extends APMClientFragment
//OR
public class GlobalFragment extends APMClientDialogFragment
Add the following methods in your GlobalFragment
onViewCreated(Fragment fragment);
onResume(Fragment fragment);
onPause(Fragment fragment);
onDestroyView(Fragment fragment);
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
APMClientFragmentUtils.onViewCreated(this);
}
@Override
public void onResume() {
super.onResume();
APMClientFragmentUtils.onResume(this);
}
@Override
public void onPause() {
super.onPause();
APMClientFragmentUtils.onPause(this);
}
@Override
public void onDestroyView() {
super.onDestroyView();
APMClientFragmentUtils.onDestroyView(this);
}
You're done with the installation !
You should be able to see our SDK on your application.

And the banner appear !
Head to the next section to start integrating our SDK into your app's features.
Last modified 1yr ago