Documentation
Search…
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
    🔗

Conditions and minimum requirements

Minimum Android version: 4.1 (API 16)
This guide was written under the assumption that you use Android Studio

I. Installation

Add the following lines to your top-level build.gradlefile.
root/build.gradle
1
Properties properties = new Properties()
2
properties.load(project.rootProject.file('local.properties').newDataInputStream())
3
4
//You can set login and password in env variables
5
def mavenAppsmilesUsername = System.getenv("APPSMILES_ARTIFACTORY_LOGIN") ?: ''
6
def mavenAppsmilesPassword = System.getenv("APPSMILES_ARTIFACTORY_PASSWORD") ?: ''
7
8
//Or in local.properties
9
def folder = new File( 'local.properties' )
10
if( folder.exists() ) {
11
properties.load(project.rootProject.file('local.properties').newDataInputStream())
12
mavenAppsmilesUsername = properties.getProperty("maven_appsmiles.username") ?: mavenAppsmilesUsername
13
mavenAppsmilesPassword = properties.getProperty("maven_appsmiles.password") ?: mavenAppsmilesPassword
14
}
15
16
allprojects {
17
repositories {
18
//...
19
20
maven {
21
url 'https://artifactory.appsmiles.eu/artifactory/list/appsmiles/'
22
credentials {
23
username = mavenAppsmilesUsername
24
password = mavenAppsmilesPassword
25
}
26
}
27
}
28
}
Copied!
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 file
root/app/build.gradle
1
dependencies {
2
//...
3
implementation 'com.moonmiles.apm:apm:6.0.1'
4
//...
5
}
Copied!
The weight of an android application containing our SDK will approximately increase by 2.5 MB

Android dependencies

Our SDK uses the dependencies appcompat, recyclerview and lottie to work. You can overwrite them in your module's build.gradle:
build.gradle
1
dependencies {
2
implementation 'androidx.appcompat:appcompat:1.2.0'
3
implementation 'androidx.recyclerview:recyclerview:1.1.0'
4
implementation 'com.airbnb.android:lottie:3.5.0'
5
}
Copied!
For more information about appcompat and recyclerview, click here For more information about lottie, click here

Security dependencies (TLS 1.2 for Android 4.1 – 4.4)

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:
1
implementation 'com.google.android.gms:play-services-base:16.1.0'
Copied!

II. Configuration

Set (1) the permissions in your AndroidManifest.xml
AndroidManifest.xml
1
<manifest ...>
2
...
3
<!-- (1) Permissions -->
4
<!-- required -->
5
<uses-permission android:name="android.permission.INTERNET" />
6
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
7
<!-- optional -->
8
<uses-permission android:name="android.permission.VIBRATE"/>
9
10
...
11
</manifest>
Copied!
Add the following lines for ProGuard
proguard-rules.pro
1
# app's miles
2
-keep class com.moonmiles.** { *; }
3
-keep interface com.moonmiles.** { *; }
Copied!

III. Initialization

In YourAppApplication.java, in the method onCreate(), retrieve an instance of APM and init the SDK with your credentials environments
MyApplication.java
1
@Override
2
public void onCreate() {
3
super.onCreate();
4
5
String partnerId = getResources().getString(R.string.ConfigPartnerID);
6
String partnerSecret = getResources().getString(R.string.ConfigPartnerSecret);
7
String appId = getPackageName();
8
String baseUrl = getResources().getString(R.string.ConfigBaseUrl);
9
10
//Init SDK APM
11
APM apm = APM.sharedInstance(this); //this == Context
12
apm.initApp(partnerId, partnerSecret, appId);
13
apm.setBaseUrl(baseUrl);
14
}
Copied!
You can declare multiple environments using the application's packageName or you can specifically declare environments with the appId variable.
MyApplication.java
1
@Override
2
public void onCreate() {
3
super.onCreate();
4
5
String partnerId = getResources().getString(R.string.ConfigPartnerID);
6
String partnerSecret = getResources().getString(R.string.ConfigPartnerSecret);
7
8
String appId;
9
String baseUrl;
10
if(SANDBOX) {
11
appId = "com.your_company.your_app_sandbox";
12
baseUrl = "https://api-sb.appsmiles.eu/";
13
}
14
else {
15
appId = "com.your_company.your_app";
16
baseUrl = "https://api-prod1.appsmiles.eu/"
17
}
18
19
//Init SDK APM
20
APM apm = APM.sharedInstance(this); //this == Context
21
apm.initApp(partnerId, partnerSecret, appId);
22
apm.setBaseUrl(baseUrl);
23
}
Copied!
Environment
URL
PRODUCTION
https://api-prod1.appsmiles.eu/
SANDOX
https://api-sb.appsmiles.eu/
We host projects on multiple servers, double check with us or your team to verify the base URL.

IV. Attaching

For this last step, you must attach our SDK to your GlobalActivity and GlobalFragment

Attaching to an « Activity »

Automatically
Manually
You can extend your GlobalActivity with APMClientAppCompatActivity or APMClientFragmentActivity
1
public class GlobalActivity extends APMClientAppCompatActivity
2
//OR
3
public class GlobalActivity extends APMClientFragmentActivity
Copied!
Add the following methods in your GlobalActivity
    onCreate(Activity activity);
    onResume(Activity activity);
    onPause(Activity activity);
    onDestroy(Activity activity);
    onNewIntent(Activity activity, Intent intent);
1
@Override
2
protected void onCreate(Bundle savedInstanceState) {
3
super.onCreate(savedInstanceState);
4
APMClientActivityUtils.onCreate(this);
5
}
6
7
@Override
8
protected void onResume() {
9
super.onResume();
10
APMClientActivityUtils.onResume(this);
11
}
12
13
@Override
14
protected void onPause() {
15
super.onPause();
16
APMClientActivityUtils.onPause(this);
17
}
18
19
@Override
20
protected void onDestroy() {
21
super.onDestroy();
22
APMClientActivityUtils.onDestroy(this);
23
}
24
25
@Override
26
protected void onNewIntent(Intent intent) {
27
super.onNewIntent(intent);
28
APMClientActivityUtils.onNewIntent(this, intent);
29
}
Copied!

Attaching to a « Fragment »

Automatically
Manually
You can extend your GlobalFragment with APMClientFragment or APMClientDialogFragment
1
public class GlobalFragment extends APMClientFragment
2
//OR
3
public class GlobalFragment extends APMClientDialogFragment
Copied!
Add the following methods in your GlobalFragment
    onViewCreated(Fragment fragment);
    onResume(Fragment fragment);
    onPause(Fragment fragment);
    onDestroyView(Fragment fragment);
1
@Override
2
public void onViewCreated(View view, Bundle savedInstanceState) {
3
super.onViewCreated(view, savedInstanceState);
4
APMClientFragmentUtils.onViewCreated(this);
5
}
6
7
@Override
8
public void onResume() {
9
super.onResume();
10
APMClientFragmentUtils.onResume(this);
11
}
12
13
@Override
14
public void onPause() {
15
super.onPause();
16
APMClientFragmentUtils.onPause(this);
17
}
18
19
@Override
20
public void onDestroyView() {
21
super.onDestroyView();
22
APMClientFragmentUtils.onDestroyView(this);
23
}
Copied!
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 26d ago