Install the SDK to your project via Gradle
in Android Studio and add the dependencies below in your app build.gradle
file.
android {.....compileOptions {sourceCompatibility JavaVersion.VERSION_1_8targetCompatibility JavaVersion.VERSION_1_8}......}dependencies {implementation 'com.geospark.android:geospark:2.2.3'}
Initialize the SDK with your PublishKey
.
//In onCreate method of your Application class include the code below.public void onCreate() {super.onCreate();GeoSpark.initialize(this, "PUBLISH_KEY");...}
GeoSpark SDK needs a User ID object to identify the device.
GeoSpark.createUser(this,"User Description", new GeoSparkCallBack() {@Overridepublic void onSuccess(GeoSparkUser geoSparkUser) {geoSparkUser.getUserId();}@Overridepublic void onFailure(GeoSparkError geoSparkError) {geoSparkError.getErrorCode();geoSparkError.getErrorMessage();}});
To start tracking the location.
//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
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);}