Grab your AppKey and AppSecret
1 - Go to https://console.mocaplatform.com and sign into your MOCA account.
2 - Select Apps item at left sidebar, and then click + New App in the content panel. Fill in the form and complete the app creation.
3 - Open the newly created app and navigate to Settings item. Select API keys tab.
4 - Get App Key
and App Secret
.
You can configure the MOCA SDK from the AndroidManifest.xml
file, or alternatively from a MOCA.properties
file
MOCA.properties file
Starting from MOCA Android SDK 1.9.0, you can configure the SDK using a MOCA.properties
file.
1 - Create an assets
folder, just inside your App's main folder.
You should be able to see a new folder in your project.
2 - Create a file called MOCA.properties
by right clicking the assets
folder and selecting New > File.
3 - Configure the SDK with the necessary keys. Please bear in mind that the only mandatory keys are AppKey, and AppSecret.
The gcmSender is mandatory only if you want to use MOCA Remote Push Notifications service.
Get your GCM Sender from Google
Check this guide in order to get your Cloud Messaging Sender Id.
Don't forget to paste the AppKey and AppSecret with the ones corresponding to your App. Otherwise the SDK won't be able to connect to MOCA Cloud.
Contents of the MOCA.properties
file:
#MOCA App key and app secret. You can get this keys from the MOCA Console.
appKey = YOUR-MOCA-APP-KEY
appSecret = YOUR-MOCA-APP-SECRET
#MOCA SDK Log level. Possible values [Off, Error, Warning, Info, Debug, Verbose]
logLevel = Debug
# MOCA Remote Push Notifications
# disable it if you have your own/ other remote push implementation
remotePushNotificationsService = true
# MOCA Proximity Service includes beacon and geofence detection
proximityService = true
# MOCA GeoTracking Service generates geo points periodically for analytics
geoTrackingService = true
# MOCA Event Tracking Service. If enabled, activates event tracking (Sessions, custom events etc.)
eventTrackingService = true
# MOCA driver. This is required for Bluetooth Beacon detection. Set it to false if a custom
# beacon driver is being used
mocaDriver = true
# Background location. Allows geoTracking in background
backgroundLocation = true
# GCM Sender ID. Only needed if you are using MOCA Remote Push Notifications.
gcmSender = YOUR-GCM-SENDER-ID
# Beacon detection engine profile [LowLatency, Balanced, BatterySaver, Custom]
# LowLatency = Notifications will be delivered almost instantly in foreground and background.
# but will have an important impact on the user's device battery.
# Balanced = Notifications are delivered almost instantly in foreground. In background it can
# take up to one minute. In Android Lollipop, Marshmallow, and N there are operating system
# optimizations that reduce the notification delay (Default setting).
# BatterySaver = Detections in foreground can take up to one minute, and in background up to
#5 minutes. this is the recommended setting for analytics-only usages.
#
beaconProfile = Balanced
# If beaconProfile is "Custom", the following parameters are mandatory
# foregroundTimeBetweenScans: Time between each scan in milliseconds, close scans means faster response, but
# more battery consumption.
# foregroundScanDuration: Time while device will be listening bluetooth signals in milliseconds.
# We recommend at least 1100 ms, so if your beacon broadcasts a signal each 350 Hz,~3 packets
# will be received.
# backgroundTimeBetweenScans: Same than foregroundTimeBetweenScans, but when device is in the background.
# this is the most important setting in terms of battery consumption.
# backgroundScanDuration: Same than foregroundScanDuration but in background.
# Uncomment these parameters in case you want to use a Custom profile
# foregroundTimeBetweenScans = 3300
# foregroundScanDuration = 3300
# backgroundTimeBetweenScans = 60000
# backgroundScanDuration = 5001
# MOCA Beacon detection settings (approximate distance in meters)
# distance detection is strongly dependent on hardware, and device calibration.
# Parameter indicates the threshold for the next zone, starting in 0
# Default config: 0-1m: immediate, 1m-5m: immediate, >5m far
# Uncomment the following lines if you want to override this settings.
# proximityImmediate= 1
# proximityNear = 5
# Required for Wi-Fi beacon detection. If your project does not include detecting
# Wi-Fi Beacons, comment out the following line
wifiProximity = true
# ACTIVE_SCANNING: When a user gets into a geofence that contains Wi-Fi beacons
# MOCA SDK performs a Wi-Fi scan once every 60 seconds in background and once # every 30 seconds in foreground.
# PASSIVE_SCANNING: SDK will never initiate any Wi-Fi Scan. But if another app
# or the systems performs a Wi-Fi Scanning, the SDK will use this information
# to determine if the device is nearby a Wi-Fi Beacon.
wifiScanningMode = ACTIVE_SCANNING
#Other settings
#Used to delay load of HTML overlay until App is ready to show it.
#experienceOverlay.delayAfterNotificationTapMs = 1000
#Cache in MB
cacheSize = 100
#Data fetch interval in milliseconds. Defaults to 1 hour
dataFetchInterval = 3600000
#Event upload interval. Defaults to 15 minutes.
eventUploadInterval = 900000
moca.CUSTOM_PUSH_ICON = @drawable/ic_moca_logo
Initializing MOCA in the Application class
We are ready to initialize MOCA SDK!
MOCA SDK must be initialized in the onCreate()
method of your Application class:
1 - If you don't have one, create a new class that inherits from Application. You will need to declare the name of this class in the AndroidManifest.xml
file. As you can see in the AndroidManifest.xml section above.
2 - Import com.innoquant.moca.*
package into your main Application class.
3 - Initialize MOCA SDK in the onCreate
method of this class.
public class MocaApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
// Init MOCA library
MOCA.initializeSDK(this);
}
}
4 - Declare the Application class in your app AndroidManifest.xml
Do not initialize MOCA within an Activity
By doing so, MOCA won't be able to manage background events.