Download library from: https://support.salesmanago.com/developers/
Example Gradle configuration:
To add the library to the project put an aar file in libs catalog and modify gradle.Build file
Parameter ‘name’ in the ‘compile’ section should be named the same as the library file without the extension.
repositories { flatDir { dirs 'libs' } } dependencies { compile(name:'appmanagolibrary-release', ext:'aar') }
For other tools configuration check how to add the external library to the project in their documentation.
List of dependencies used by the library:
androidx.appcompat:appcompat:1.6.1 androidx.legacy:legacy-support-v4:1.0.0 androidx.media:media:1.6.0 com.google.firebase:firebase-messaging:21.1.0 com.google.android.gms:play-services-location:21.0.1 com.google.android.gms:play-services-base:18.2.0 androidx.constraintlayout:constraintlayout:2.1.4 com.squareup.picasso:picasso:2.8 com.google.code.gson:gson:2.10.1
Library configuration
In the strings.xml file of integrated application add the following entries:
- appmanago_launch_time
It defines the time interval between successive uses of the module/function after which we
assume that the application was restarted. The value is given in minutes.<string name="appmanago_launch_time">30</string>
For 30 – launch event will be registered when the application has been inactive for 30 minutes and then resumed.
- appmanago_sync_meantime
It/ Variable/ The entry defines how often the platform should make an attempt to synchronize events, which took place when there was no Internet connection. The value is given in minutes.<string name="appmanago_sync_meantime">360</string>
In the example application will try to synchronize every 360 minutes.
- appmanago_endpoint
It/ Variable/ The entry defines the endpoint. Default endpoint for SALESmanago Mobile is<string name="appmanago_endpoint">https://api.appmanago.com</string>
- appmanago_vendor_id
Vendor identificator; itan be found after logging in to the SALESmanago Mobile panel Settings -> Account.<string name="appmanago_vendor_id">VENDOR_ID</string>
- appmanago_application_id
Simple ID of the application.The ID is created when you add a new application to Create app panel.<string name="appmanago_application_id">APPLICATION_SIMPLE_ID</string>
- appmanago_gps_sync_time
Minimal interval between sending GPS coordinates (in minutes).<string name="appmanago_gps_sync_time">1</string>
- appmanago_gps_front_available
Flag determining whether the location should be updated continuously or only when the application is active (0 – still, 1 – only when the application is active).<string name="appmanago_gps_front_available">0</string>
- appmanago_gps_accuracy
Accuracy of location determination and also battery consumption:
– HIGH – high accuracy, the device will determine the most accurate location,
– BALANCED – (recommended) – accuracy up to 100m with the best ratio of performance to battery consumption,
– LOW – accuracy up to 10km, low battery consumption,
– PASSIVE – passive mode, the application is waiting for the location to be updated by other applications, it does not use energy to determine it,
(to avoid battery drain, location system has 10s timeout – if within 10 second location is not resolved, process will be canceled)<string name="appmanago_gps_accuracy">HIGH</string>
Transferring events to SALESmanago Mobile
Events are transferred via AmMonitoring interface. The initialization of such an object looks as shown below and takes place under the onCreate()
method:
private AmMonitoring amMonitor;
amMonitor = AmMonitor.initLibrary(getApplicationContext());
AmMonitor objects should be created per module as they contain components responsible for measuring the time spent in the module (Activity).
Additionally, the onResume()
and onPause()
methods, required to measure the time spent in a given module, must be overridden. The module name must be the same as the one defined on the SALESmanago Mobile platform.
@Override protected void onResume() { super.onResume(); amMonitor.eventStarted(MODULE_NAME, new AmProperties()); } @Override protected void onPause() { super.onPause(); amMonitor.eventEnded(MODULE_NAME, new AmProperties()); }
Starting from library version 3.7.0, the code line provided below must be added to the Activity
class of the module that is displayed to the user first (i.e., the starting screen):
ActivityLifecycleListener.registerActivityLifecycleCallback(CONTEXT);
where CONTEXT
is the application context – a global context tied to the lifecycle of an application, providing access to application-level resources and services.
The above code line should be placed in the onCreate
method, preferably directly after calling the super.onCreate(savedInstanceState)
method, as shown below:
public class FirstScreenActivityClass extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ActivityLifecycleListener.registerActivityLifecycleCallback((Application) getApplicationContext()); } }
Integration with Firebase Cloud Messaging (FCM)
To add FCM to the application one must execute client’s manual on Google page:
https://firebase.google.com/docs/cloud-messaging/android/client
In order to receive Server API Key and Sender ID one should register the application. Then, add API and ID to the GCM account in SALESmanago Mobile. Those values can be found in Settings -> Cloud Messaging after logging in to the project in the Firebase console. One should also integrate the android project with FCM using the ready tool in Android Studio Tools -> Firebase -> Cloud Messaging.
The next step is adding the permissions and services to AndroidManisfest.xml:
<service android:name="com.appmanago.lib.fcm.AmFirebaseListenerService"> <intent-filter> <action android:name="com.google.firebase.MESSAGING_EVENT" /> </intent-filter> </service>
Additionally, check the Google Api service for onCreate() method.
if (checkPlayServices()) { amMonitor.resolveRegistrationToken(); }
Implementation is as follows:
private boolean checkPlayServices() { GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance(); int resultCode = apiAvailability.isGooglePlayServicesAvailable(this); if (resultCode != ConnectionResult.SUCCESS) { if (apiAvailability.isUserResolvableError(resultCode)) { apiAvailability.getErrorDialog(this, resultCode, 9000) .show(); } else { Log.i(Constants.LOG_TAG, "This device is not supported."); finish(); } return false; } return true; }
Rich notification
It is able to add rich notification to push e.g. a image. In create push it is necessary to check “Rich content” checkbox and add needed attributes. It is recommended to make it custom but it is possible to use the default implementation. For default in SALESmanago Mobile library when it is received push with rich notification with type “jpg” or “png” and link to picture then it will show this image below notification.
To use custom rich notification it is need to override richPushNotification() method in class PushActionExecutor To do this it is necessary to change class in AndroidManifest.xml com.appmanago.lib.fcm.AmFirebaseListenerService to new class that creates instead PushActionExecutor its extension with override richPushNotification() method.
Beacon
Beacons are avaiable on Android since Android Lollipop when it supports Bluetooth LE. It is need to add to AndroidManifest.xml permissions to Bluetooth:
<uses-permission android:name="android.permission.BLUETOOTH"/> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
In place where we start to search for beacons we need to initialize SALESmanago Mobile library to support searching beacons:
amBeaconMonitor = AmBeaconMonitor.initLibrary(getApplicationContext());
Before search it is needed to check if:
– Android version is above or equals Lollipop
– Bluetooth is reached in device and it is on
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if(mBluetoothAdapter != null && mBluetoothAdapter.isEnabled()) { mBluetoothLeScanner = mBluetoothAdapter.getBluetoothLeScanner(); mBluetoothLeScanner.startScan( amBeaconMonitor.getScanFilter(BEACON_UUID), amBeaconMonitor.getScanSettings(), amBeaconMonitor.getScanCallback()); } }
To stop searching Beacons:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mBluetoothLeScanner.stopScan(amBeaconMonitor.getScanCallback()); }
The methods used to monitor customer behavior:
amMonitor.eventStarted(ACTIVITY_NAME, amProperties);
is used during the launch of the module / (Activity). ACTIVITY_NAME is simpleID from SALESmanago Mobile.
Usually the method will be called in the method onResume() where it’ll start to start count duration of the module usage.
amMonitor.eventEnded(ACTIVITY_NAME, amProperties);
is used at the end of (Activity) module execution.
Usually it will be used in the method OnPause() where it’ll stop counting the time of module usage.
amMonitor.eventCustom(CUSTOM_EVENT_NAME, amProperties);
is used during the custom events transfer. The events should be defined in SALESmanago Mobile as custom events as well.
amMonitor.clicked(FUNCTION_NAME, amProperties);
is used during the launch of methods mapped in SALESmanago Mobile. It will count how many times function was used. You can add details like date as amProperties.
amMonitor.syncEmail(EMAIL_ADDRESS);
is used to add user’s email address. The email will be used as user’s ID on the platform.
amMonitor.syncMsisdn(PHONE_NUMBER);
is used to add users phone number/MSISDN.
amMonitor.sendUserProperties(PROPERTIES_MAP);
It sends user properties to SALESmanago Mobile. It is a key-value map where we can store data about user, e.g., name, surname, shoe number or birthdate. We can use this data to personalize push notifications, and set the dynamic segments.
amMonitor.sendLocation(WIDTH, LENGTH);
is used to send users’location.
AmExtras amExtras = amMonitor.getAmExtras(bundle) amExtras.getPayload(); amExtras.getPushType();
It allows the application to read the type and content of payload from the notification. It is executed when user receives a push. A developer can use the data from payload to e.g., redirect to app’s module, send an event, view an image, and many more.