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.gradle
file.
root/build.gradle
Copy 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
root/app/build.gradle
Copy 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:
build.gradle
Copy 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:
otherwise, you need to add this dependency :
Copy 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
AndroidManifest.xml
Copy <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
Copy # 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
MyApplication.java
Copy @ 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
Copy @ 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 »
Automatically Manually
You can extend your GlobalActivity with APMClientAppCompatActivity or APMClientFragmentActivity
Copy 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);
Copy @ 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);
}
Attaching to a « Fragment »
Automatically Manually
You can extend your GlobalFragment with APMClientFragment or APMClientDialogFragment
Copy 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);
Copy @ 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.
Head to the next section to start integrating our SDK into your app's features .