Advanced mode

Enabling TLS 1.2 (Support 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

Connect/Create an account automatically

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

Update an account automatically

You can update an app’s miles account automatically with the method APMUIServicesUser.userClientSave() This method needs : « userId »

String email = edittextEmail.getText().toString();
String firstname = edittextFirstname.getText().toString();
String lastname = edittextLastname.getText().toString();
String mobile = edittextMobile.getText().toString();
String city = edittextCity.getText().toString();
String birthday = edittextBirthday.getText().toString();
String userId = edittextUserId.getText().toString();
HashMap segments = null
APMUIServicesUser.userClientSave(email,
firstname,
lastname,
mobile,
APMServicesConfig.APM_K_USER_GENDER_M + "",
birthday,
city,
null,
userId,
segments,
new APMUserSaveListener()
{
@Override
public void userSaveSuccess(APMUser user)
{
Log.e("Test", "user : " + user + " updated !");
Toast.makeText(RegisterActivity.this, "user : " + user + " updated !", Toast.LENGTH_SHORT).show();
}
@Override
public void failure(APMException exception)
{
Toast.makeText(RegisterActivity.this, exception.errorMessage, Toast.LENGTH_SHORT).show();
}
});

Logout an account automatically

You can logout an app’s miles account automatically with the method APMUIServicesUser.userLogout()

APMUIServicesUser.userLogout(this, new APMUserLogoutListener()
{
@Override
public void userLogoutSuccess()
{
Toast.makeText(RegisterActivity.this, "Logout success !", Toast.LENGTH_SHORT).show();
}
@Override
public void failure(APMException exception)
{
Toast.makeText(RegisterActivity.this, exception.errorMessage, Toast.LENGTH_SHORT).show();
}
});

The badge is automatically refreshes

UserProperties

Use the class APMUserPropertiesUtils to manager user properties fo user.

key : Property keys are strings. (e.g. « zipcode », « profession »). value :Property values are strings. (e.g. « 33000 », « doctor »).

You can add user properties with the followings methods :

addUserProperty(String userProperty, String key);
addUserProperties(HashMap userProperties);

For remove one user property, you can use :

removeUserProperty(String key);

or for remove all user properties :

removeUserProperties(),

If you need to refresh SDK after set your UserProperties, you can call :

APMServicesPublic.sharedInstance().refreshSDK(true);

Segments

You can pass a segmentation during connection with the method APMUIServicesUser.userClientConnect()

//Segments
HashMap segments = new HashMap();
segments.put("1", "green"); //Axe 1 : color
segments.put("2", "1998"); //Axe 2 : year
APMUIServicesUser.userClientConnect(/*....*/, segments, /*....*/)

Override click on the badge

You can override the click on the badge with the method APMBadgeManager.setOnBadgeClickListener()

APMBadgeManager badgeManager = APMPublic.sharedInstanceBadgeManagerPrivate();
badgeManager.setOnBadgeClickListener(new APMOnBadgeClickListener()
{
@Override
public boolean onBadgeClick(int badge)
{
if(badge == APMConfig.APM_BADGE_INIT)
Log.d("APMOnBadgeClickListener", "Click on the badge init !");
else if(badge == APMConfig.APM_BADGE_OTHER_WIN)
Log.d("APMOnBadgeClickListener", "Click on the badge other win !");
else if(badge == APMConfig.APM_BADGE_WIN)
Log.d("APMOnBadgeClickListener", "Click on the badge win !");
else if(badge == APMConfig.APM_BADGE_GIFT)
Log.d("APMOnBadgeClickListener", "Click on the badge gift !");
else if(badge == APMConfig.APM_BADGE_INFOS)
Log.d("APMOnBadgeClickListener", "Click on the badge infos !");
else if(badge == APMConfig.APM_BADGE_ADMIN)
Log.d("APMOnBadgeClickListener", "Click on the badge admin !");
return true;
}
});

Comment : Return true if the event was handled, false otherwise.

Show/Hide badge

You can hide the badge with the method :

APMPublic.sharedInstance(this).hideBadge();

And show the badge :

APMPublic.sharedInstance(this).showBadge();

Comment : The method APMUIServicesUser.userClientConnect() use theses methods to hide and show the badge after connection success.

Debug Mode

APMPublic.sharedInstance(this).setDebugMode(true); //To show trace log app's miles

Onboarding (get events with listener)

For retrieve events of onboarding. Use class APMOnboardingUtils and APMOnboardingUtilsListener. Example with AbstractActivity lifecycle.

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
}
@Override
public void apmOnboardingButtonLaterClicked()
{
//Get the event OnboardingButtonLaterClicked
}
@Override
public void apmOnboardingButtonNeverClicked()
{
//Get the event OnboardingButtonNeverClicked
}
}

For retrieve events of deepLinks. Use class APMDeepLinkActionUtils and APMDeepLinkActionUtilsListener. Example with AbstractActivity lifecycle.

public class AbstractActivity extends FragmentActivity implements APMDeepLinkActionUtilsListener
{
//...
//Declare a object of APMDeepLinkActionUtils in your class
private APMDeepLinkActionUtils mDeepLinkActionUtils;
@Override
protected void onCreate(@Nullable final Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//...
//Activity become the listener on events of deepLinks
mDeepLinkActionUtils = new APMDeepLinkActionUtils(this);
}
@Override
protected void onResume()
{
super.onResume();
//...
//Listen events of deepLinks
mDeepLinkActionUtils.register(this);
}
@Override
protected void onPause()
{
super.onPause();
//...
//Unlisten events of deepLinks
mDeepLinkActionUtils.unregister(this);
}
@Override
public void apmDeepLinkActionButtonGoClicked(String deepLinkUrl, String action, HashMap params)
{
//Get the event DeepLinkActionButtonGoClicked
}
}

APMServicesUserListener

You can be notify when the user changed with the class APMServicesUserListener Set a listener with

APMServicesPublic.sharedInstance().setServicesUserListener(this);

Get the callback with the method apmServicesUserChanged

@Override
public void apmServicesUserChanged(APMUser user)
{
Log.i("APMServices", "apmServicesUserChanged : "+user);
}

Communicate with a WebView

You can communicate with APM natively with your Webview. Here, methods that reachable via APMJavaScriptInterface :

  • APMPublic.sharedInstance(context).registerAction(activity, action1);

  • APMPublic.sharedInstance(context).triggerAction(activity, actionName);

Implement your own WebViewClient

public class MyWebViewClient extends WebViewClient
{
protected FragmentActivity activity;
public MyWebViewClient(FragmentActivity activity)
{
super();
this.activity = activity;
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
boolean urlCatched = APMJavaScriptInterface.handleUrlSchemeAppsmiles(activity, view, url);
if(urlCatched) //Url catched, so return true for webView don't load url
return true;
return super.shouldOverrideUrlLoading(view, url);
}
}

In your WebViewActivity.m, set MyWebViewClient in your webview

webView.setWebViewClient(new MyWebViewClient(this));

Don’t forget to enable javascript

webView.getSettings().setJavaScriptEnabled(true);

Implement this JS method :

function execute(url)
{
var iframe = document.createElement("IFRAME");
iframe.setAttribute("src", url);
document.documentElement.appendChild(iframe);
iframe.parentNode.removeChild(iframe);
iframe = null;
}

registerAction(Android) == addActions(JS)

Call addActions appsmilessdk://addActions/+PARAMS in your webview to call registerActionin Android PARAMS is a JSONObject converted to String :

{
"classID":"product",
"actions":
[
{
"labels":["label 1", "label 2", "label 3"],
"props":["property 1", "property 2", "property 3"]
}
]
}

Example :

execute("appsmilessdk://addActions/{"classID":"product", "actions":[{"labels":["Clic sur un produit", "Clic sur un produit de la catégorie Google", "Clic sur le produit GOOGLE !"], "props":["click_product", "categoryID=1", "productID=1"]}]}");

triggerAction(Android) == triggerAction(JS)

Call triggerAction appsmilessdk://triggerAction/+ACTION_NAME in your webview to call triggerActionin Android ACTION_NAME is a String

Example :

execute("appsmilessdk://triggerAction/click_product"); //click_product == ACTION_NAME