Quickstart

Integrate our SDK in your android app.

Step 1 : Install SDK

Install the SDK to your project via Gradle in Android Studio and add the dependencies below in your app build.gradle file.

dependencies {
implementation'com.geospark.android:geospark:2.2.5'
}

Step 2: Initialize SDK

Initialize the SDK with your PublishKey.

Java
Kotlin
Java
//In onCreate method of your Application class include the code below.
public void onCreate() {
super.onCreate();
GeoSpark.initialize(this, "PUBLISH_KEY");
...
}
Kotlin
override fun onCreate() {
super.onCreate()
GeoSpark.initialize(this, "PUBLISH_KEY")
...
}

Step 3: Create user

GeoSpark SDK needs a User ID object to identify the device.

Java
Kotlin
Java
GeoSpark.createUser(this,"User Description", new GeoSparkCallBack() {
@Override
public void onSuccess(GeoSparkUser geoSparkUser) {
geoSparkUser.getUserId();
}
@Override
public void onFailure(GeoSparkError geoSparkError) {
geoSparkError.getErrorCode();
geoSparkError.getErrorMessage();
}
});
Kotlin
GeoSpark.createUser(this, "User Description", object : GeoSparkCallBack {
override fun onSuccess(geoSparkUser: GeoSparkUser) {
geoSparkUser.userId
}
override fun onFailure(geoSparkError: GeoSparkError) {
geoSparkError.errorCode
geoSparkError.errorMessage
}
})

Step 4: Start Location Tracking

To start tracking the location.

Java
Kotlin
Java
//To enable location, call the requestLocationPermissions and
//requestLocationServices method.
if(!GeoSpark.checkLocationPermission(this)) {
GeoSpark.requestLocationPermission(this);
} else if (!GeoSpark.checkLocationServices(this)) {
GeoSpark.requestLocationServices(this);
} else{
//Call this method to start tracking the location.
GeoSpark.startTracking(this);
}
Kotlin
//To enable location, call the requestLocationPermissions and
//requestLocationServices method.
if(!GeoSpark.checkLocationPermission(this)) {
GeoSpark.requestLocationPermission(this)
} else if (!GeoSpark.checkLocationServices(this)) {
GeoSpark.requestLocationServices(this)
} else{
//Call this method to start tracking the location.
GeoSpark.startTracking(this)
}

To start tracking the location above Android 10

Java
Kotlin
Java
if (!GeoSpark.checkActivityPermission(this)) {
GeoSpark.requestActivityPermission(this);
} else if (!GeoSpark.checkLocationPermission(this)) {
GeoSpark.requestLocationPermission(this);
} else if (!GeoSpark.checkBackgroundLocationPermission(this)) {
GeoSpark.requestBackgroundLocationPermission(this);
} else if (!GeoSpark.checkLocationServices(this)) {
GeoSpark.requestLocationServices(this);
} else {
GeoSpark.startTracking(this);
}
Kotlin
if (!GeoSpark.checkActivityPermission(this)) {
GeoSpark.requestActivityPermission(this)
} else if (!GeoSpark.checkLocationPermission(this)) {
GeoSpark.requestLocationPermission(this)
} else if (!GeoSpark.checkBackgroundLocationPermission(this)) {
GeoSpark.requestBackgroundLocationPermission(this)
} else if (!GeoSpark.checkLocationServices(this)) {
GeoSpark.requestLocationServices(this)
} else {
GeoSpark.startTracking(this)
}