Quickstart

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

Estimated time: 20 minutes

This guide will go over:

  • Conditions and minimum requirements

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.

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 file

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

Android dependencies

Our SDK uses the dependencies appcompat, recyclerview and lottie to work. You can overwrite them in your module's 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 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:

implementation 'com.google.android.gms:play-services-base:16.1.0'

More informations here : https://developer.android.com/training/articles/security-gms-provider.html

II. Configuration

Set (1) the permissions in your 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

# app's miles
-keep class com.moonmiles.** { *; }
-keep interface com.moonmiles.** { *; }

III. Initialization

In YourAppApplication.java, in the method onCreate(), retrieve an instance of APM and init the SDK with your credentials environments

@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.

@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); 
}

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 »

You can extend your GlobalActivity with APMClientAppCompatActivity or APMClientFragmentActivity

public class GlobalActivity extends APMClientAppCompatActivity
//OR
public class GlobalActivity extends APMClientFragmentActivity

Attaching to a « Fragment »

You can extend your GlobalFragment with APMClientFragment or APMClientDialogFragment

public class GlobalFragment extends APMClientFragment
//OR
public class GlobalFragment extends APMClientDialogFragment

You're done with the installation !

You should be able to see our SDK on your application.

Head to the next section to start integrating our SDK into your app's features.

Last updated