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
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
allprojects {
repositories {
//...
maven {
url 'https://artifactory.appsmiles.eu/artifactory/list/appsmiles/'
credentials {
username = properties.getProperty("maven_appsmiles.username")
password = properties.getProperty("maven_appsmiles.password")
}
}
}
}

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
dependencies {
//...
implementation 'com.moonmiles.apm:apm:4.1.3'
//...
}

The weight of an android application containing our SDK will approximately increase by 2.5 MB

Android dependencies

Our SDK uses the dependencies appcompat-v7, recyclerview-v7 and lottie to work. You can overwrite them in your module's build.gradle:

build.gradle
dependencies {
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.airbnb.android:lottie:2.7.0'
}

For more information about appcompat-v7 and recyclerview-v7, 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, (2) the partnerId and the partnerSecret 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"/>
...
<application ...>
...
<!-- (2) app's miles partnerId and partnerSecret -->
<meta-data android:name="com.moonmiles.partnerID" android:value="@string/ConfigPartnerID" />
<meta-data android:name="com.moonmiles.partnerSecret" android:value="@string/ConfigPartnerSecret" />
</application>
</manifest>

III. Initialization

In YourAppApplication.java, in the method onCreate(), retrieve an instance of APM and set the baseUrl of our API.

Environment

URL

PRODUCTION

https://api-prod1.appsmiles.eu/

SANDOX

https://api-sb.appsmiles.eu/

MyApplication.java
APM apm = APMPublic.sharedInstance(this); //this == Context
apm.setBaseUrl(<URL_API>);

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 main or abstract Activity/Fragment.

Attaching to an « Activity »

Add the following methods in your GlobalActivity

  • APMPublic.sharedInstance(this).onCreate(savedInstanceState, getIntent());

  • APMPublic.sharedInstance(this).onResume(this, getIntent());

  • APMPublic.sharedInstance(this).onNewIntent(intent);

  • APMPublic.sharedInstance(this).onPause();

  • APMPublic.sharedInstance(this).onActivityResult(requestCode, resultCode, data);

AbstractActivity.java
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
APMPublic.sharedInstance(this).onCreate(savedInstanceState, getIntent());
}
@Override
protected void onResume()
{
super.onResume();
APMPublic.sharedInstance(this).onResume(this, getIntent());
}
@Override
protected void onNewIntent(Intent intent)
{
super.onNewIntent(intent);
APMPublic.sharedInstance(this).onNewIntent(intent);
}
@Override
protected void onPause()
{
super.onPause();
APMPublic.sharedInstance(this).onPause();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
APMPublic.sharedInstance(this).onActivityResult(requestCode, resultCode, data);
}

Attaching to a « Fragment »

If your application uses Fragments to show entire screens, add the following method to the appropriate fragments or their Abstract class:

AbstractFragment.java
@Override
public void onResume()
{
super.onResume();
Activity activity = getActivity();
APMPublic.sharedInstance(activity).onResume(activity, null);
}

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.