Install

1. Install

Conditions

Version Android minimum : – 4.1 (API 16) – Android Studio

Install library using Gradle

allprojects {
    repositories {
        //...
        maven { url 'https://dl.bintray.com/moonmiles/appsmiles' }
    }
}

//...

compile 'com.moonmiles.apm:apm:3.1.8'

Install library manually

  • Download library APM (3.1.8) here

  • Add the following code in the build.gradle file in your module

    repositories {
        flatDir {
            dirs 'libs'
        }
    }
    dependencies {
        compile 'com.moonmiles.apm:apm-3.1.8@aar'
    }

Note : The file apm-3.1.8.aar weighs approximately 1 MB, once installed on an android phone, the weight of an android application containing the SDK will be increased approximately by 2.5 MB

Add dependency appcompat-v7 and recyclerview-v7

This SDK needs the dependency appcompat-v7 and recyclerview-v7 from google to work. Add theses dependencies in build.gradle

dependencies {
    implementation 'com.android.support:appcompat-v7:27.0.2'
    implementation 'com.android.support:recyclerview-v7:27.0.2'
}

For more information about theses dependencies, click here

Add dependency play-services-base (TLS 1.2 for Android 4.1 – 4.4)

For security reasons, our server only supports HTTPS connection with a minimum TLS 1.2 protocol. Android 4.1 – 4.4 phones support TLS 1.2 with the help of Google Play Services

Our SDK needs a Google Play Service to update security, Google has several dependencies that hinder the play-services-base code. Example with Google Analytics dependency :

compile 'com.google.android.gms:play-services-analytics:10.2.4'

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

2. Integration

Use Proguard ?

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

Initialize APM, in « AndroidManifest.xml »

  • Set the partnerId and the partnerSecret in the tag <application>

    <application
        ...>
        ...
        <meta-data android:name="com.moonmiles.partnerID" android:value="@string/ConfigPartnerID" />
        <meta-data android:name="com.moonmiles.partnerSecret" android:value="@string/ConfigPartnerSecret" />
    </application>
  • Set permissions use by SDK

    <!-- 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"/>

Initialize APM, in your class « Application »

  • In YourAppApplication.java, in method onCreate(), retrieve instance of APM

    APM apm = APMPublic.sharedInstance(this); //this == Context
  • Set the baseUrl of API https://api.appsmiles.eu/ (PRODUCTION) https://api-sandbox.appsmiles.eu/ (SANDBOX)

    apm.setBaseUrl(<URL_API>); 

Enable APM for a « 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);

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

Enable APM for a « Fragment »

If your application use Fragment for show entire screen, add the following method

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

3. Connection client

Use the method APMUIServicesUser.userClientConnect() for connect automatically your user to app’s miles. If no account exist with this informations, the server create automatically this account. This method needs : « email », « userID » and « optIn » « email » is the email of user « userID » is a unique identifier in your database – « optIn » is the RGPD OptIn

If you don’t want pass the email, you can build a encrypted email with the userID, for example : 123456789@appsmiles.fr – 123456789 is the userID

String email = edittextEmail.getText().toString(); //Required
String userId = edittextUserId.getText().toString(); //Required

//optIn, APM_DEVICE_OPT_IN_NOT_SET, APM_DEVICE_OPT_IN_REFUSE, APM_DEVICE_OPT_IN_ACCEPT 
Integer optIn = APMServicesConfig.APM_DEVICE_OPT_IN_ACCEPT; //Required

APMUIServicesUser.userClientConnect(email, userId, optIn, new APMUserConnectListener()
{
    @Override
    public void userConnectSuccess(APMUser user)
    {
        Log.e("Test", user + " connected !");
    }

    @Override
    public void failure(APMException exception)
    {
        Log.e("Test", "error : "+exception);
    }
});

4. Show/Hide badge

If you want to hide the badge on some screens

APMPublic.sharedInstance(this).hideBadge();

Don’t forget to re-show badge after hiding

APMPublic.sharedInstance(this).showBadge();

5. Tagging plan

Call triggerAction for send a tag

APMPublic.sharedInstance(this).triggerAction("display_product"); 
//this --> Context
//"display_product" --> actionName

6. Onboarding process

Implements this for :– app’s miles account and client account not connected, so, redirect user to your process login/register account– app’s miles account not connected and client account connected, so, connect app’s miles account with method userClientConnect– app’s miles account and client account connected, so, nothing

public class AbstractActivity extends FragmentActivity implements APMOnboardingUtilsListener
{
    //...

    //Declare a object of APMOnboardingUtils in your class
    private APMOnboardingUtils mOnboardingUtils; 

    @Override
    protected void onCreate(@Nullable final Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        //...

        //AbstractActivity become the listener on events of onboarding
        mOnboardingUtils = new APMOnboardingUtils(this);
    }

    @Override
    protected void onResume()
    {
        super.onResume();
        //...

        //Listen events of onboarding
        mOnboardingUtils.register(this);
    }

    @Override
    protected void onPause()
    {
        super.onPause();
        //...

        //Unlisten events of onboarding
        mOnboardingUtils.unregister(this);
    }

    @Override
    public void apmOnboardingButtonOkClicked()
    {
        //Get the event OnboardingButtonOkClicked
        boolean clientAccountConnected = true;
        if(clientAccountConnected) //TODO check if account client is connected
        {
            //Account client is connected

            APMServices services = APMServicesPublic.sharedInstance(MyApplication.this);
            if(services.getUser() != null && services.getUser().isConnected())
            {
                //Client account connected and app's miles account connected
                Log.i("TAG", "Client account connected and app's miles account connected");
            }
            else
            {
                //Client account connected --> need to connect app's miles account
                Log.w("TAG", "Client account connected --> need to connect app's miles account");
                apmConnection(MyApplication.this);
            }
        }
        else
        {
            //TODO show screen login/create account
        }
    }

    @Override
    public void apmOnboardingButtonLaterClicked() { }

    @Override
    public void apmOnboardingButtonNeverClicked() { }
}

Last updated